Merge branch 'shared-vector'
This commit is contained in:
+14
-11
@@ -2,45 +2,48 @@ TOP=../..
|
||||
|
||||
include $(TOP)/configure/CONFIG
|
||||
|
||||
PROD_LIBS += pvData Com
|
||||
|
||||
PROD_HOST += testThread
|
||||
testThread_SRCS += testThread.cpp
|
||||
testThread_LIBS += pvData Com
|
||||
|
||||
PROD_HOST += testTimer
|
||||
testTimer_SRCS += testTimer.cpp
|
||||
testTimer_LIBS += pvData Com
|
||||
|
||||
PROD_HOST += testBitSet
|
||||
testBitSet_SRCS += testBitSet.cpp
|
||||
testBitSet_LIBS += pvData Com
|
||||
|
||||
PROD_HOST += testByteOrder
|
||||
testByteOrder_SRCS += testByteOrder.cpp
|
||||
testByteOrder_LIBS += Com
|
||||
|
||||
PROD_HOST += testByteBuffer
|
||||
testByteBuffer_SRCS += testByteBuffer.cpp
|
||||
testByteBuffer_LIBS += pvData Com
|
||||
|
||||
PROD_HOST += testBaseException
|
||||
testBaseException_SRCS += testBaseException.cpp
|
||||
testBaseException_LIBS += pvData Com
|
||||
|
||||
PROD_HOST += testSerialization
|
||||
TESTPROD += testSerialization
|
||||
testSerialization_SRCS += testSerialization.cpp
|
||||
testSerialization_LIBS += pvData Com
|
||||
TESTS += testSerialization
|
||||
|
||||
PROD_HOST += testTimeStamp
|
||||
testTimeStamp_SRCS += testTimeStamp.cpp
|
||||
testTimeStamp_LIBS += pvData Com
|
||||
|
||||
PROD_HOST += testQueue
|
||||
testQueue_SRCS += testQueue.cpp
|
||||
testQueue_LIBS += pvData Com
|
||||
|
||||
PROD_HOST += testMessageQueue
|
||||
testMessageQueue_SRCS += testMessageQueue.cpp
|
||||
testMessageQueue_LIBS += pvData Com
|
||||
|
||||
TESTPROD += testTypeCast
|
||||
testTypeCast_SRCS += testTypeCast.cpp
|
||||
TESTS += testTypeCast
|
||||
|
||||
TESTPROD += testSharedVector
|
||||
testSharedVector_SRCS += testSharedVector.cpp
|
||||
TESTS += testSharedVector
|
||||
|
||||
TESTSCRIPTS_HOST += $(TESTS:%=%.t)
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
#----------------------------------------
|
||||
|
||||
+202
-401
@@ -12,7 +12,9 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
#include <dbDefs.h> // for NELEMENTS
|
||||
|
||||
#include <epicsExit.h>
|
||||
#include <pv/pvIntrospect.h>
|
||||
@@ -45,6 +47,8 @@
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
namespace {
|
||||
|
||||
static SerializableControl* flusher;
|
||||
static DeserializableControl* control;
|
||||
static ByteBuffer* buffer;
|
||||
@@ -122,14 +126,23 @@ void serializationTest(PVFieldPtr const & field) {
|
||||
deserializedField->deserialize(buffer, control);
|
||||
|
||||
// must equal
|
||||
bool isEqual = getConvert()->equals(*field,*deserializedField);
|
||||
assert(isEqual);
|
||||
if(*field==*deserializedField)
|
||||
testPass("Serialization round trip OK");
|
||||
else {
|
||||
testFail("Serialization round trip did not match!");
|
||||
std::string buf;
|
||||
field->toString(&buf);
|
||||
testDiag("Expected: %s", buf.c_str());
|
||||
buf.clear();
|
||||
deserializedField->toString(&buf);
|
||||
testDiag("Found: %s", buf.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void testEquals(std::ostream& ofile) {
|
||||
ofile<<"Testing equals...\n";
|
||||
void testEquals() {
|
||||
testDiag("Testing equals...");
|
||||
PVDataCreatePtr factory = getPVDataCreate();
|
||||
assert(factory.get()!=NULL);
|
||||
testOk1(factory.get()!=NULL);
|
||||
|
||||
// be sure all is covered
|
||||
for (int i = pvBoolean; i < pvString; i++)
|
||||
@@ -138,32 +151,63 @@ void testEquals(std::ostream& ofile) {
|
||||
|
||||
PVScalarPtr scalar1 = factory->createPVScalar(scalarType);
|
||||
PVScalarPtr scalar2 = factory->createPVScalar(scalarType);
|
||||
assert((*scalar1)==(*scalar2));
|
||||
testOk1((*scalar1)==(*scalar2));
|
||||
|
||||
PVScalarArrayPtr array1 = factory->createPVScalarArray(scalarType);
|
||||
PVScalarArrayPtr array2 = factory->createPVScalarArray(scalarType);
|
||||
assert((*array1)==(*array2));
|
||||
testOk1((*array1)==(*array2));
|
||||
}
|
||||
|
||||
// and a structure
|
||||
PVStructurePtr structure1 = factory->createPVStructure(getStandardField()->timeStamp());
|
||||
PVStructurePtr structure2 = factory->createPVStructure(getStandardField()->timeStamp());
|
||||
assert((*structure1)==(*structure2));
|
||||
testOk1((*structure1)==(*structure2));
|
||||
|
||||
// and a structure array
|
||||
PVStructureArrayPtr structureArray1 = factory->createPVStructureArray(getFieldCreate()->createStructureArray(structure1->getStructure()));
|
||||
PVStructureArrayPtr structureArray2 = factory->createPVStructureArray(getFieldCreate()->createStructureArray(structure2->getStructure()));
|
||||
assert((*structureArray1)==(*structureArray2));
|
||||
|
||||
ofile<<"!!! PASSED\n\n";
|
||||
testOk1((*structureArray1)==(*structureArray2));
|
||||
}
|
||||
|
||||
void testScalar(std::ostream& ofile) {
|
||||
ofile<<"Testing scalars...\n";
|
||||
PVDataCreatePtr factory = getPVDataCreate();
|
||||
assert(factory.get()!=NULL);
|
||||
template<typename PVT>
|
||||
void testScalarType()
|
||||
{
|
||||
typedef typename PVT::value_type value_type;
|
||||
|
||||
ofile<<"\tPVBoolean\n";
|
||||
testDiag("type %s", ScalarTypeFunc::name(PVT::typeCode));
|
||||
|
||||
typename PVT::shared_pointer pv = std::tr1::static_pointer_cast<PVT>(getPVDataCreate()->createPVScalar(PVT::typeCode));
|
||||
|
||||
pv->put(0);
|
||||
serializationTest(pv);
|
||||
pv->put(42);
|
||||
serializationTest(pv);
|
||||
pv->put(std::numeric_limits<value_type>::max()-1);
|
||||
serializationTest(pv);
|
||||
pv->put(std::numeric_limits<value_type>::max());
|
||||
serializationTest(pv);
|
||||
|
||||
if(std::numeric_limits<value_type>::min()!=0) {
|
||||
pv->put(-42);
|
||||
serializationTest(pv);
|
||||
pv->put(std::numeric_limits<value_type>::min()+1);
|
||||
serializationTest(pv);
|
||||
pv->put(std::numeric_limits<value_type>::min());
|
||||
serializationTest(pv);
|
||||
}
|
||||
|
||||
if(std::numeric_limits<value_type>::has_infinity) {
|
||||
pv->put(std::numeric_limits<value_type>::infinity());
|
||||
serializationTest(pv);
|
||||
}
|
||||
}
|
||||
|
||||
void testScalar() {
|
||||
testDiag("Testing scalars...");
|
||||
PVDataCreatePtr factory = getPVDataCreate();
|
||||
testOk1(factory.get()!=NULL);
|
||||
|
||||
testDiag("type %s", ScalarTypeFunc::name(pvBoolean));
|
||||
PVBooleanPtr pvBoolean =
|
||||
std::tr1::static_pointer_cast<PVBoolean>(factory->createPVScalar(epics::pvData::pvBoolean));
|
||||
pvBoolean->put(false);
|
||||
@@ -171,196 +215,19 @@ void testScalar(std::ostream& ofile) {
|
||||
pvBoolean->put(true);
|
||||
serializationTest(pvBoolean);
|
||||
|
||||
ofile<<"\tPVByte\n";
|
||||
PVBytePtr pvByte =
|
||||
std::tr1::static_pointer_cast<PVByte>(factory->createPVScalar(epics::pvData::pvByte));
|
||||
pvByte->put(0);
|
||||
serializationTest(pvByte);
|
||||
pvByte->put(12);
|
||||
serializationTest(pvByte);
|
||||
pvByte->put(BYTE_MAX_VALUE);
|
||||
serializationTest(pvByte);
|
||||
pvByte->put(BYTE_MIN_VALUE);
|
||||
serializationTest(pvByte);
|
||||
|
||||
ofile<<"\tPVShort\n";
|
||||
PVShortPtr pvShort =
|
||||
std::tr1::static_pointer_cast<PVShort>(factory->createPVScalar(epics::pvData::pvShort));
|
||||
pvShort->put(0);
|
||||
serializationTest(pvShort);
|
||||
pvShort->put(123);
|
||||
serializationTest(pvShort);
|
||||
pvShort->put(BYTE_MAX_VALUE);
|
||||
serializationTest(pvShort);
|
||||
pvShort->put(BYTE_MIN_VALUE);
|
||||
serializationTest(pvShort);
|
||||
pvShort->put(SHORT_MAX_VALUE);
|
||||
serializationTest(pvShort);
|
||||
pvShort->put(SHORT_MIN_VALUE);
|
||||
serializationTest(pvShort);
|
||||
|
||||
ofile<<"\tPVInt\n";
|
||||
PVIntPtr pvInt =
|
||||
std::tr1::static_pointer_cast<PVInt>(factory->createPVScalar(epics::pvData::pvInt));
|
||||
pvInt->put(0);
|
||||
serializationTest(pvInt);
|
||||
pvInt->put(123456);
|
||||
serializationTest(pvInt);
|
||||
pvInt->put(BYTE_MAX_VALUE);
|
||||
serializationTest(pvInt);
|
||||
pvInt->put(BYTE_MIN_VALUE);
|
||||
serializationTest(pvInt);
|
||||
pvInt->put(SHORT_MAX_VALUE);
|
||||
serializationTest(pvInt);
|
||||
pvInt->put(SHORT_MIN_VALUE);
|
||||
serializationTest(pvInt);
|
||||
pvInt->put(INT_MAX_VALUE);
|
||||
serializationTest(pvInt);
|
||||
pvInt->put(INT_MIN_VALUE);
|
||||
serializationTest(pvInt);
|
||||
|
||||
ofile<<"\tPVLong\n";
|
||||
PVLongPtr pvLong =
|
||||
std::tr1::static_pointer_cast<PVLong>(factory->createPVScalar(epics::pvData::pvLong));
|
||||
pvLong->put(0);
|
||||
serializationTest(pvLong);
|
||||
pvLong->put(12345678901LL);
|
||||
serializationTest(pvLong);
|
||||
pvLong->put(BYTE_MAX_VALUE);
|
||||
serializationTest(pvLong);
|
||||
pvLong->put(BYTE_MIN_VALUE);
|
||||
serializationTest(pvLong);
|
||||
pvLong->put(SHORT_MAX_VALUE);
|
||||
serializationTest(pvLong);
|
||||
pvLong->put(SHORT_MIN_VALUE);
|
||||
serializationTest(pvLong);
|
||||
pvLong->put(INT_MAX_VALUE);
|
||||
serializationTest(pvLong);
|
||||
pvLong->put(INT_MIN_VALUE);
|
||||
serializationTest(pvLong);
|
||||
pvLong->put(LONG_MAX_VALUE);
|
||||
serializationTest(pvLong);
|
||||
pvLong->put(LONG_MIN_VALUE);
|
||||
serializationTest(pvLong);
|
||||
testScalarType<PVByte>();
|
||||
testScalarType<PVUByte>();
|
||||
testScalarType<PVShort>();
|
||||
testScalarType<PVUShort>();
|
||||
testScalarType<PVInt>();
|
||||
testScalarType<PVUInt>();
|
||||
testScalarType<PVLong>();
|
||||
testScalarType<PVULong>();
|
||||
testScalarType<PVFloat>();
|
||||
testScalarType<PVDouble>();
|
||||
|
||||
|
||||
ofile<<"\tPVUByte\n";
|
||||
PVUBytePtr pvUByte =
|
||||
std::tr1::static_pointer_cast<PVUByte>(factory->createPVScalar(epics::pvData::pvUByte));
|
||||
pvUByte->put(0);
|
||||
serializationTest(pvUByte);
|
||||
pvUByte->put(12);
|
||||
serializationTest(pvUByte);
|
||||
pvUByte->put(UBYTE_MAX_VALUE);
|
||||
serializationTest(pvUByte);
|
||||
pvUByte->put(BYTE_MAX_VALUE);
|
||||
serializationTest(pvUByte);
|
||||
pvUByte->put(BYTE_MIN_VALUE);
|
||||
serializationTest(pvUByte);
|
||||
|
||||
ofile<<"\tPVUShort\n";
|
||||
PVUShortPtr pvUShort =
|
||||
std::tr1::static_pointer_cast<PVUShort>(factory->createPVScalar(epics::pvData::pvUShort));
|
||||
pvUShort->put(0);
|
||||
serializationTest(pvUShort);
|
||||
pvUShort->put(1234);
|
||||
serializationTest(pvUShort);
|
||||
pvUShort->put(BYTE_MAX_VALUE);
|
||||
serializationTest(pvUShort);
|
||||
pvUShort->put(BYTE_MIN_VALUE);
|
||||
serializationTest(pvUShort);
|
||||
pvUShort->put(UBYTE_MAX_VALUE);
|
||||
serializationTest(pvUShort);
|
||||
pvUShort->put(SHORT_MAX_VALUE);
|
||||
serializationTest(pvUShort);
|
||||
pvUShort->put(SHORT_MIN_VALUE);
|
||||
serializationTest(pvUShort);
|
||||
pvUShort->put(USHORT_MAX_VALUE);
|
||||
serializationTest(pvUShort);
|
||||
|
||||
ofile<<"\tPVInt\n";
|
||||
PVIntPtr pvUInt =
|
||||
std::tr1::static_pointer_cast<PVInt>(factory->createPVScalar(epics::pvData::pvUInt));
|
||||
pvUInt->put(0);
|
||||
serializationTest(pvUInt);
|
||||
pvUInt->put(123456);
|
||||
serializationTest(pvUInt);
|
||||
pvUInt->put(BYTE_MAX_VALUE);
|
||||
serializationTest(pvUInt);
|
||||
pvUInt->put(BYTE_MIN_VALUE);
|
||||
serializationTest(pvUInt);
|
||||
pvUInt->put(UBYTE_MAX_VALUE);
|
||||
serializationTest(pvUInt);
|
||||
pvUInt->put(SHORT_MAX_VALUE);
|
||||
serializationTest(pvUInt);
|
||||
pvUInt->put(SHORT_MIN_VALUE);
|
||||
serializationTest(pvUInt);
|
||||
pvUInt->put(USHORT_MAX_VALUE);
|
||||
serializationTest(pvUInt);
|
||||
pvUInt->put(INT_MAX_VALUE);
|
||||
serializationTest(pvUInt);
|
||||
pvUInt->put(INT_MIN_VALUE);
|
||||
serializationTest(pvUInt);
|
||||
pvUInt->put(UINT_MAX_VALUE);
|
||||
serializationTest(pvUInt);
|
||||
|
||||
ofile<<"\tPVLong\n";
|
||||
PVLongPtr pvULong =
|
||||
std::tr1::static_pointer_cast<PVLong>(factory->createPVScalar(epics::pvData::pvULong));
|
||||
pvULong->put(0);
|
||||
serializationTest(pvULong);
|
||||
pvULong->put(12345678901LL);
|
||||
serializationTest(pvULong);
|
||||
pvULong->put(BYTE_MAX_VALUE);
|
||||
serializationTest(pvULong);
|
||||
pvULong->put(BYTE_MIN_VALUE);
|
||||
serializationTest(pvULong);
|
||||
pvULong->put(UBYTE_MAX_VALUE);
|
||||
serializationTest(pvULong);
|
||||
pvULong->put(SHORT_MAX_VALUE);
|
||||
serializationTest(pvULong);
|
||||
pvULong->put(SHORT_MIN_VALUE);
|
||||
serializationTest(pvULong);
|
||||
pvULong->put(USHORT_MAX_VALUE);
|
||||
serializationTest(pvULong);
|
||||
pvULong->put(INT_MAX_VALUE);
|
||||
serializationTest(pvULong);
|
||||
pvULong->put(INT_MIN_VALUE);
|
||||
serializationTest(pvULong);
|
||||
pvULong->put(UINT_MAX_VALUE);
|
||||
serializationTest(pvULong);
|
||||
pvULong->put(LONG_MAX_VALUE);
|
||||
serializationTest(pvULong);
|
||||
pvULong->put(LONG_MIN_VALUE);
|
||||
serializationTest(pvULong);
|
||||
pvULong->put(ULONG_MAX_VALUE);
|
||||
serializationTest(pvULong);
|
||||
|
||||
ofile<<"\tPVFloat\n";
|
||||
PVFloatPtr pvFloat =
|
||||
std::tr1::static_pointer_cast<PVFloat>(factory->createPVScalar(epics::pvData::pvFloat));
|
||||
pvFloat->put(0);
|
||||
serializationTest(pvFloat);
|
||||
pvFloat->put(12.345);
|
||||
serializationTest(pvFloat);
|
||||
pvFloat->put(FLOAT_MAX_VALUE);
|
||||
serializationTest(pvFloat);
|
||||
pvFloat->put(FLOAT_MIN_VALUE);
|
||||
serializationTest(pvFloat);
|
||||
|
||||
ofile<<"\tPVDouble\n";
|
||||
PVDoublePtr pvDouble =
|
||||
std::tr1::static_pointer_cast<PVDouble>(factory->createPVScalar(epics::pvData::pvDouble));
|
||||
pvDouble->put(0);
|
||||
serializationTest(pvDouble);
|
||||
pvDouble->put(12.345);
|
||||
serializationTest(pvDouble);
|
||||
pvDouble->put(DOUBLE_MAX_VALUE);
|
||||
serializationTest(pvDouble);
|
||||
pvDouble->put(DOUBLE_MIN_VALUE);
|
||||
serializationTest(pvDouble);
|
||||
|
||||
ofile<<"\tPVString\n";
|
||||
testDiag("type %s", ScalarTypeFunc::name(pvString));
|
||||
PVStringPtr pvString =
|
||||
std::tr1::static_pointer_cast<PVString>(factory->createPVScalar(epics::pvData::pvString));
|
||||
pvString->put("");
|
||||
@@ -377,167 +244,88 @@ void testScalar(std::ostream& ofile) {
|
||||
// huge string test
|
||||
pvString->put(String(10000, 'a'));
|
||||
serializationTest(pvString);
|
||||
|
||||
// TODO unsigned test
|
||||
|
||||
ofile<<"!!! PASSED\n\n";
|
||||
}
|
||||
|
||||
void testArray(std::ostream& ofile) {
|
||||
ofile<<"Testing arrays...\n";
|
||||
template<typename PVT>
|
||||
void testArrayType(const typename PVT::value_type* rdata, size_t len)
|
||||
{
|
||||
typedef typename PVT::value_type value_type;
|
||||
|
||||
PVDataCreatePtr factory = getPVDataCreate();
|
||||
assert(factory.get()!=NULL);
|
||||
typename PVT::svector empty(0), data(len);
|
||||
|
||||
ofile<<"\tPVBooleanArray\n";
|
||||
//bool boolEmpty[] = { false };
|
||||
//bool bv[] = { false, true, false, true, true };
|
||||
PVBooleanArrayPtr pvBoolean =
|
||||
std::tr1::static_pointer_cast<PVBooleanArray>(factory->createPVScalarArray(epics::pvData::pvBoolean));
|
||||
//pvBoolean->put(0, 0, boolEmpty, 0);
|
||||
serializationTest(pvBoolean);
|
||||
//pvBoolean->put(0, 5, bv, 0);
|
||||
serializationTest(pvBoolean);
|
||||
std::copy(rdata, rdata+len, data.begin());
|
||||
|
||||
ofile<<"\tPVByteArray\n";
|
||||
int8 byteEmpty[] = { 0 };
|
||||
int8 byv[] = { 0, 1, 2, -1, BYTE_MAX_VALUE, BYTE_MAX_VALUE-1,
|
||||
BYTE_MIN_VALUE+1, BYTE_MIN_VALUE };
|
||||
PVByteArrayPtr pvByte =
|
||||
std::tr1::static_pointer_cast<PVByteArray>(factory->createPVScalarArray(epics::pvData::pvByte));
|
||||
pvByte->put(0, 0, byteEmpty, 0);
|
||||
serializationTest(pvByte);
|
||||
pvByte->put(0, 8, byv, 0);
|
||||
serializationTest(pvByte);
|
||||
testDiag("type %s", ScalarTypeFunc::name(PVT::typeCode));
|
||||
|
||||
ofile<<"\tPVShortArray\n";
|
||||
int16 shortEmpty[] = { 0 };
|
||||
int16 sv[] = { 0, 1, 2, -1, SHORT_MAX_VALUE, SHORT_MAX_VALUE-1,
|
||||
SHORT_MIN_VALUE+1, SHORT_MIN_VALUE };
|
||||
PVShortArrayPtr pvShort =
|
||||
std::tr1::static_pointer_cast<PVShortArray>(factory->createPVScalarArray(epics::pvData::pvShort));
|
||||
pvShort->put(0, 0, shortEmpty, 0);
|
||||
serializationTest(pvShort);
|
||||
pvShort->put(0, 8, sv, 0);
|
||||
serializationTest(pvShort);
|
||||
typename PVT::shared_pointer pv = std::tr1::static_pointer_cast<PVT>(getPVDataCreate()->createPVScalarArray(PVT::typeCode));
|
||||
|
||||
ofile<<"\tPVIntArray\n";
|
||||
int32 intEmpty[] = { 0 };
|
||||
int32 iv[] = { 0, 1, 2, -1, INT_MAX_VALUE, INT_MAX_VALUE-1,
|
||||
INT_MIN_VALUE+1, INT_MIN_VALUE };
|
||||
PVIntArrayPtr pvInt =
|
||||
std::tr1::static_pointer_cast<PVIntArray>(factory->createPVScalarArray(epics::pvData::pvInt));
|
||||
pvInt->put(0, 0, intEmpty, 0);
|
||||
serializationTest(pvInt);
|
||||
pvInt->put(0, 8, iv, 0);
|
||||
serializationTest(pvInt);
|
||||
|
||||
ofile<<"\tPVLongArray\n";
|
||||
int64 longEmpty[] = { 0 };
|
||||
int64 lv[] = { 0, 1, 2, -1, LONG_MAX_VALUE, LONG_MAX_VALUE-1,
|
||||
LONG_MIN_VALUE+1, LONG_MIN_VALUE };
|
||||
PVLongArrayPtr pvLong =
|
||||
std::tr1::static_pointer_cast<PVLongArray>(factory->createPVScalarArray(epics::pvData::pvLong));
|
||||
pvLong->put(0, 0, longEmpty, 0);
|
||||
serializationTest(pvLong);
|
||||
pvLong->put(0, 8, lv, 0);
|
||||
serializationTest(pvLong);
|
||||
|
||||
ofile<<"\tPVUByteArray\n";
|
||||
uint8 ubyteEmpty[] = { 0 };
|
||||
uint8 ubyv[] = { 0, 1, 2, -1, BYTE_MAX_VALUE, BYTE_MAX_VALUE-1,
|
||||
BYTE_MIN_VALUE+1, BYTE_MIN_VALUE, UBYTE_MAX_VALUE };
|
||||
PVUByteArrayPtr pvUByte =
|
||||
std::tr1::static_pointer_cast<PVUByteArray>(factory->createPVScalarArray(epics::pvData::pvUByte));
|
||||
pvUByte->put(0, 0, ubyteEmpty, 0);
|
||||
serializationTest(pvUByte);
|
||||
pvUByte->put(0, 9, ubyv, 0);
|
||||
serializationTest(pvUByte);
|
||||
|
||||
ofile<<"\tPVUShortArray\n";
|
||||
uint16 ushortEmpty[] = { 0 };
|
||||
uint16 usv[] = { 0, 1, 2, -1, SHORT_MAX_VALUE, SHORT_MAX_VALUE-1,
|
||||
SHORT_MIN_VALUE+1, SHORT_MIN_VALUE, USHORT_MAX_VALUE };
|
||||
PVUShortArrayPtr pvUShort =
|
||||
std::tr1::static_pointer_cast<PVUShortArray>(factory->createPVScalarArray(epics::pvData::pvUShort));
|
||||
pvUShort->put(0, 0, ushortEmpty, 0);
|
||||
serializationTest(pvUShort);
|
||||
pvUShort->put(0, 8, usv, 0);
|
||||
serializationTest(pvUShort);
|
||||
|
||||
ofile<<"\tPVUIntArray\n";
|
||||
uint32 uintEmpty[] = { 0 };
|
||||
uint32 uiv[] = { 0, 1, 2, -1, INT_MAX_VALUE, INT_MAX_VALUE-1,
|
||||
INT_MIN_VALUE+1, INT_MIN_VALUE, UINT_MAX_VALUE };
|
||||
PVUIntArrayPtr pvUInt =
|
||||
std::tr1::static_pointer_cast<PVUIntArray>(factory->createPVScalarArray(epics::pvData::pvUInt));
|
||||
pvUInt->put(0, 0, uintEmpty, 0);
|
||||
serializationTest(pvUInt);
|
||||
pvUInt->put(0, 9, uiv, 0);
|
||||
serializationTest(pvUInt);
|
||||
|
||||
ofile<<"\tPVULongArray\n";
|
||||
uint64 ulongEmpty[] = { 0 };
|
||||
uint64 ulv[] = { 0, 1, 2, -1, LONG_MAX_VALUE, LONG_MAX_VALUE-1,
|
||||
LONG_MIN_VALUE+1, LONG_MIN_VALUE, ULONG_MAX_VALUE };
|
||||
PVULongArrayPtr pvULong =
|
||||
std::tr1::static_pointer_cast<PVULongArray>(factory->createPVScalarArray(epics::pvData::pvULong));
|
||||
pvULong->put(0, 0, ulongEmpty, 0);
|
||||
serializationTest(pvULong);
|
||||
pvULong->put(0, 9, ulv, 0);
|
||||
serializationTest(pvULong);
|
||||
|
||||
ofile<<"\tPVFloatArray\n";
|
||||
float floatEmpty[] = { (float)0.0 };
|
||||
float fv[] = { (float)0.0, (float)1.1, (float)2.3, (float)-1.4,
|
||||
FLOAT_MAX_VALUE, FLOAT_MAX_VALUE-(float)123456.789, FLOAT_MIN_VALUE
|
||||
+(float)1.1, FLOAT_MIN_VALUE };
|
||||
PVFloatArrayPtr pvFloat =
|
||||
std::tr1::static_pointer_cast<PVFloatArray>(factory->createPVScalarArray(epics::pvData::pvFloat));
|
||||
pvFloat->put(0, 0, floatEmpty, 0);
|
||||
serializationTest(pvFloat);
|
||||
pvFloat->put(0, 8, fv, 0);
|
||||
serializationTest(pvFloat);
|
||||
|
||||
ofile<<"\tPVDoubleArray\n";
|
||||
double doubleEmpty[] = { (double)0.0 };
|
||||
double dv[] = { (double)0.0, (double)1.1, (double)2.3, (double)-1.4,
|
||||
DOUBLE_MAX_VALUE, DOUBLE_MAX_VALUE-(double)123456.789,
|
||||
DOUBLE_MIN_VALUE+(double)1.1, DOUBLE_MIN_VALUE };
|
||||
PVDoubleArrayPtr pvDouble =
|
||||
std::tr1::static_pointer_cast<PVDoubleArray>(factory->createPVScalarArray(epics::pvData::pvDouble));
|
||||
pvDouble->put(0, 0, doubleEmpty, 0);
|
||||
serializationTest(pvDouble);
|
||||
pvDouble->put(0, 8, dv, 0);
|
||||
serializationTest(pvDouble);
|
||||
|
||||
ofile<<"\tPVStringArray\n";
|
||||
String stringEmpty[] = { "" };
|
||||
String
|
||||
strv[] =
|
||||
{
|
||||
"",
|
||||
"a",
|
||||
"a b",
|
||||
" ",
|
||||
"test",
|
||||
"smile",
|
||||
"this is a little longer string... maybe a little but longer... this makes test better",
|
||||
String(10000, 'b') };
|
||||
PVStringArrayPtr pvString =
|
||||
std::tr1::static_pointer_cast<PVStringArray>(factory->createPVScalarArray(epics::pvData::pvString));
|
||||
pvString->put(0, 0, stringEmpty, 0);
|
||||
serializationTest(pvString);
|
||||
pvString->put(0, 8, strv, 0);
|
||||
serializationTest(pvString);
|
||||
|
||||
ofile<<"!!! PASSED\n\n";
|
||||
pv->replace(freeze(empty));
|
||||
serializationTest(pv);
|
||||
pv->replace(freeze(data));
|
||||
serializationTest(pv);
|
||||
}
|
||||
|
||||
void testNonInitialized(std::ostream& ofile) {
|
||||
ofile<<"Testing non-initialized...\n";
|
||||
static const boolean bdata[] = {0, 1, 0, 1, 1};
|
||||
|
||||
static const int8 i8data[] = { 0, 1, 2, -1, BYTE_MAX_VALUE, BYTE_MAX_VALUE-1,
|
||||
BYTE_MIN_VALUE+1, BYTE_MIN_VALUE };
|
||||
static const uint8 u8data[] = { 0, 1, 2, -1, UBYTE_MAX_VALUE, UBYTE_MAX_VALUE-1 };
|
||||
|
||||
static const int16 i16data[] = { 0, 1, 2, -1, SHORT_MAX_VALUE, SHORT_MAX_VALUE-1,
|
||||
SHORT_MIN_VALUE+1, SHORT_MIN_VALUE };
|
||||
static const uint16 u16data[] = { 0, 1, 2, -1, USHORT_MAX_VALUE, USHORT_MAX_VALUE-1 };
|
||||
|
||||
static const int32 i32data[] = { 0, 1, 2, -1, INT_MAX_VALUE, INT_MAX_VALUE-1,
|
||||
INT_MIN_VALUE+1, INT_MIN_VALUE };
|
||||
static const uint32 u32data[] = { 0, 1, 2, -1, UINT_MAX_VALUE, UINT_MAX_VALUE-1 };
|
||||
|
||||
static const int64 i64data[] = { 0, 1, 2, -1, LONG_MAX_VALUE, LONG_MAX_VALUE-1,
|
||||
LONG_MIN_VALUE+1, LONG_MIN_VALUE };
|
||||
static const uint64 u64data[] = { 0, 1, 2, -1, ULONG_MAX_VALUE, ULONG_MAX_VALUE-1 };
|
||||
|
||||
static const double ddata[] = { (double)0.0, (double)1.1, (double)2.3, (double)-1.4,
|
||||
DOUBLE_MAX_VALUE, DOUBLE_MAX_VALUE-(double)123456.789,
|
||||
DOUBLE_MIN_VALUE+(double)1.1, DOUBLE_MIN_VALUE };
|
||||
|
||||
static const float fdata[] = { (float)0.0, (float)1.1, (float)2.3, (float)-1.4,
|
||||
FLOAT_MAX_VALUE, FLOAT_MAX_VALUE-(float)123456.789,
|
||||
FLOAT_MIN_VALUE+(float)1.1, FLOAT_MIN_VALUE };
|
||||
|
||||
static const String sdata[] = {
|
||||
"",
|
||||
"a",
|
||||
"a b",
|
||||
" ",
|
||||
"test",
|
||||
"smile",
|
||||
"this is a little longer string... maybe a little but longer... this makes test better",
|
||||
String(10000, 'b')
|
||||
};
|
||||
|
||||
void testArray() {
|
||||
testDiag("Testing arrays...");
|
||||
|
||||
testArrayType<PVBooleanArray>(bdata, NELEMENTS(bdata));
|
||||
|
||||
testArrayType<PVByteArray>(i8data, NELEMENTS(i8data));
|
||||
testArrayType<PVUByteArray>(u8data, NELEMENTS(u8data));
|
||||
testArrayType<PVShortArray>(i16data, NELEMENTS(i16data));
|
||||
testArrayType<PVUShortArray>(u16data, NELEMENTS(u16data));
|
||||
testArrayType<PVIntArray>(i32data, NELEMENTS(i32data));
|
||||
testArrayType<PVUIntArray>(u32data, NELEMENTS(u32data));
|
||||
testArrayType<PVLongArray>(i64data, NELEMENTS(i64data));
|
||||
testArrayType<PVULongArray>(u64data, NELEMENTS(u64data));
|
||||
|
||||
testArrayType<PVDoubleArray>(ddata, NELEMENTS(ddata));
|
||||
testArrayType<PVFloatArray>(fdata, NELEMENTS(fdata));
|
||||
|
||||
testArrayType<PVStringArray>(sdata, NELEMENTS(sdata));
|
||||
}
|
||||
|
||||
void testNonInitialized() {
|
||||
testDiag("Testing non-initialized...");
|
||||
PVDataCreatePtr factory = getPVDataCreate();
|
||||
assert(factory.get()!=NULL);
|
||||
testOk1(factory.get()!=NULL);
|
||||
|
||||
// be sure all is covered
|
||||
for (int i = pvBoolean; i < pvString; i++)
|
||||
@@ -558,17 +346,15 @@ void testNonInitialized(std::ostream& ofile) {
|
||||
// and a structure array
|
||||
PVStructureArrayPtr structureArray = factory->createPVStructureArray(getFieldCreate()->createStructureArray(structure->getStructure()));
|
||||
serializationTest(structureArray);
|
||||
|
||||
ofile<<"!!! PASSED\n\n";
|
||||
}
|
||||
|
||||
void testStructure(std::ostream& ofile) {
|
||||
ofile<<"Testing structure...\n";
|
||||
void testStructure() {
|
||||
testDiag("Testing structure...");
|
||||
|
||||
PVDataCreatePtr factory = getPVDataCreate();
|
||||
assert(factory.get()!=NULL);
|
||||
testOk1(factory.get()!=NULL);
|
||||
|
||||
ofile<<"\tSimple structure serialization\n";
|
||||
testDiag("\tSimple structure serialization");
|
||||
PVStructurePtr pvStructure = factory->createPVStructure(getStandardField()->timeStamp());
|
||||
pvStructure->getLongField("secondsPastEpoch")->put(123);
|
||||
pvStructure->getIntField("nanoSeconds")->put(456);
|
||||
@@ -576,21 +362,47 @@ void testStructure(std::ostream& ofile) {
|
||||
|
||||
serializationTest(pvStructure);
|
||||
|
||||
ofile<<"\tComplex structure serialization\n";
|
||||
testDiag("\tComplex structure serialization");
|
||||
pvStructure = factory->createPVStructure(
|
||||
getStandardField()->structureArray(
|
||||
getStandardField()->timeStamp(), "alarm,control,display,timeStamp")
|
||||
);
|
||||
// TODO fill with data
|
||||
serializationTest(pvStructure);
|
||||
}
|
||||
|
||||
ofile<<"!!! PASSED\n\n";
|
||||
void testStructureArray() {
|
||||
testDiag("Testing structure array...");
|
||||
|
||||
PVDataCreatePtr factory = getPVDataCreate();
|
||||
testOk1(factory.get()!=NULL);
|
||||
|
||||
StructureArrayConstPtr tstype(
|
||||
getFieldCreate()->createStructureArray(getStandardField()->alarm()));
|
||||
PVStructureArrayPtr pvArr = getPVDataCreate()->createPVStructureArray(tstype);
|
||||
|
||||
testDiag("empty array");
|
||||
serializationTest(pvArr);
|
||||
|
||||
pvArr->setLength(10);
|
||||
|
||||
testDiag("All NULLs");
|
||||
serializationTest(pvArr);
|
||||
|
||||
PVStructureArray::svector data(5);
|
||||
|
||||
data[1] = getPVDataCreate()->createPVStructure(getStandardField()->alarm());
|
||||
data[4] = getPVDataCreate()->createPVStructure(getStandardField()->alarm());
|
||||
|
||||
pvArr->replace(freeze(data));
|
||||
|
||||
testDiag("Some NULLs");
|
||||
serializationTest(pvArr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void testStructureId(std::ostream& ofile) {
|
||||
ofile<<"Testing structureID...\n";
|
||||
void testStructureId() {
|
||||
testDiag("Testing structureID...");
|
||||
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
|
||||
@@ -607,15 +419,13 @@ void testStructureId(std::ostream& ofile) {
|
||||
StructureConstPtr structure2 = fieldCreate->createStructure("id2", fieldNames, fields);
|
||||
|
||||
|
||||
assert(structureWithNoId!=structure1);
|
||||
assert(structure1!=structure2);
|
||||
testOk1(structureWithNoId!=structure1);
|
||||
testOk1(structure1!=structure2);
|
||||
|
||||
//serializationTest(structure1);
|
||||
|
||||
PVStructurePtr pvStructure = getPVDataCreate()->createPVStructure(structure1);
|
||||
serializationTest(pvStructure);
|
||||
|
||||
ofile<<"!!! PASSED\n\n";
|
||||
}
|
||||
|
||||
void serializatioTest(FieldConstPtr const & field)
|
||||
@@ -631,17 +441,15 @@ void serializatioTest(FieldConstPtr const & field)
|
||||
FieldConstPtr deserializedField = getFieldCreate()->deserialize(buffer, control);
|
||||
|
||||
// must equal
|
||||
bool isEqual = *field == *deserializedField;
|
||||
assert(isEqual);
|
||||
//assertEquals("field " + field.toString() + " serialization broken", field, deserializedField);
|
||||
testOk1(*field == *deserializedField);
|
||||
}
|
||||
|
||||
void testIntrospectionSerialization(std::ostream& ofile)
|
||||
void testIntrospectionSerialization()
|
||||
{
|
||||
ofile<<"Testing introspection serialization...\n";
|
||||
testDiag("Testing introspection serialization...");
|
||||
|
||||
FieldCreatePtr factory = getFieldCreate();
|
||||
assert(factory.get()!=NULL);
|
||||
testOk1(factory.get()!=NULL);
|
||||
|
||||
// be sure all is covered
|
||||
for (int i = pvBoolean; i < pvString; i++)
|
||||
@@ -662,42 +470,35 @@ void testIntrospectionSerialization(std::ostream& ofile)
|
||||
// and a structure array
|
||||
StructureArrayConstPtr structureArray = factory->createStructureArray(structure);
|
||||
serializatioTest(structureArray);
|
||||
|
||||
ofile<<"!!! PASSED\n\n";
|
||||
}
|
||||
|
||||
void testStringCopy(std::ostream& ofile) {
|
||||
void testStringCopy() {
|
||||
String s1 = "abc";
|
||||
String s2 = s1;
|
||||
if (s1.c_str() != s2.c_str())
|
||||
ofile << "\n!!! implementation of epics::pvData::String assignment operator does not share content !!!\n\n";
|
||||
testDiag("implementation of epics::pvData::String assignment operator does not share content");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
std::ofstream outfile;
|
||||
std::ostream *out=NULL;
|
||||
if(argc>1) {
|
||||
outfile.open(argv[1]);
|
||||
if(outfile.is_open()){
|
||||
out=&outfile;
|
||||
}else{
|
||||
fprintf(stderr, "Failed to open test output file\n");
|
||||
}
|
||||
}
|
||||
if(!out) out=&std::cout;
|
||||
} // end namespace
|
||||
|
||||
MAIN(testSerialization) {
|
||||
|
||||
testPlan(175);
|
||||
|
||||
flusher = new SerializableControlImpl();
|
||||
control = new DeserializableControlImpl();
|
||||
buffer = new ByteBuffer(1<<16);
|
||||
|
||||
testStringCopy(*out);
|
||||
testStringCopy();
|
||||
|
||||
testIntrospectionSerialization(*out);
|
||||
testEquals(*out);
|
||||
testNonInitialized(*out);
|
||||
testIntrospectionSerialization();
|
||||
testEquals();
|
||||
testNonInitialized();
|
||||
|
||||
testScalar(*out);
|
||||
testArray(*out);
|
||||
testStructure(*out);
|
||||
testScalar();
|
||||
testArray();
|
||||
testStructure();
|
||||
testStructureArray();
|
||||
|
||||
|
||||
delete buffer;
|
||||
@@ -705,6 +506,6 @@ int main(int argc, char *argv[]) {
|
||||
delete flusher;
|
||||
|
||||
epicsExitCallAtExits();
|
||||
return 0;
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,558 @@
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/* Author: Michael Davidsaver */
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include "pv/sharedVector.h"
|
||||
|
||||
static void testEmpty()
|
||||
{
|
||||
testDiag("Test empty vector");
|
||||
epics::pvData::shared_vector<int> empty, empty2;
|
||||
|
||||
testOk1(empty.size()==0);
|
||||
testOk1(empty.empty());
|
||||
testOk1(empty.begin()==empty.end());
|
||||
testOk1(empty.unique());
|
||||
|
||||
testOk1(empty.data()==NULL);
|
||||
|
||||
testOk1(empty==empty);
|
||||
testOk1(!(empty!=empty));
|
||||
testOk1(empty==empty2);
|
||||
testOk1(!(empty!=empty2));
|
||||
}
|
||||
|
||||
static void testInternalAlloc()
|
||||
{
|
||||
testDiag("Test vector alloc w/ new[]");
|
||||
|
||||
epics::pvData::shared_vector<int> internal(5);
|
||||
|
||||
testOk1(internal.size()==5);
|
||||
testOk1(!internal.empty());
|
||||
testOk1(internal.unique());
|
||||
testOk1(internal.data()!=NULL);
|
||||
|
||||
testOk1(internal.begin()+5==internal.end());
|
||||
testOk1(internal.begin()==internal.end()-5);
|
||||
testOk1(internal.begin()+2==internal.end()-3);
|
||||
testOk1(internal.end()-internal.begin()==5);
|
||||
|
||||
internal[2] = 42;
|
||||
testOk1(internal[2]==42);
|
||||
|
||||
epics::pvData::shared_vector<int> internal2(15, 500);
|
||||
|
||||
testOk1(internal2.size()==15);
|
||||
testOk1(internal2[1]==500);
|
||||
|
||||
internal.swap(internal2);
|
||||
|
||||
testOk1(internal2.size()==5);
|
||||
testOk1(internal.size()==15);
|
||||
|
||||
internal.clear();
|
||||
|
||||
testOk1(internal.size()==0);
|
||||
testOk1(internal.empty());
|
||||
testOk1(internal.unique());
|
||||
testOk1(internal.data()==NULL);
|
||||
}
|
||||
|
||||
namespace {
|
||||
//Note: STL shared_ptr requires that deletors be copy constructable
|
||||
template<typename E>
|
||||
struct callCounter {
|
||||
std::tr1::shared_ptr<int> count;
|
||||
callCounter():count(new int){*count=0;}
|
||||
callCounter(const callCounter& o):count(o.count) {};
|
||||
callCounter& operator=(const callCounter& o){count=o.count;}
|
||||
void operator()(E){*count=1;}
|
||||
};
|
||||
}
|
||||
|
||||
static void testExternalAlloc()
|
||||
{
|
||||
testDiag("Test vector external alloc");
|
||||
|
||||
// Simulate a failed malloc() or similar
|
||||
int *oops=0;
|
||||
epics::pvData::shared_vector<int> nullPtr(oops, 42, 100);
|
||||
|
||||
testOk1(nullPtr.size()==0);
|
||||
testOk1(nullPtr.empty());
|
||||
testOk1(nullPtr.begin()==nullPtr.end());
|
||||
testOk1(nullPtr.unique());
|
||||
|
||||
testOk1(nullPtr.data()==NULL);
|
||||
|
||||
int *raw=new int[5];
|
||||
epics::pvData::shared_vector<int> newData(raw, 1, 4);
|
||||
|
||||
testOk1(newData.size()==4);
|
||||
testOk1(!newData.empty());
|
||||
|
||||
// check that offset is used
|
||||
raw[1]=14;
|
||||
testOk1(newData[0]==14);
|
||||
|
||||
// Check use of custom deleter
|
||||
int localVar[4] = {1,2,3,4};
|
||||
callCounter<int*> tracker;
|
||||
testOk1(*tracker.count==0);
|
||||
|
||||
epics::pvData::shared_vector<int> locvar(localVar,
|
||||
tracker,
|
||||
0, 4);
|
||||
|
||||
testOk1(locvar[1]==2);
|
||||
testOk1(*tracker.count==0);
|
||||
|
||||
newData.swap(locvar);
|
||||
|
||||
testOk1(*tracker.count==0);
|
||||
|
||||
newData.clear();
|
||||
|
||||
testOk1(*tracker.count==1);
|
||||
}
|
||||
|
||||
static void testShare()
|
||||
{
|
||||
testDiag("Test vector Sharing");
|
||||
|
||||
epics::pvData::shared_vector<int> one, two(15);
|
||||
epics::pvData::shared_vector<int> three(two);
|
||||
|
||||
testOk1(one.unique());
|
||||
testOk1(!two.unique());
|
||||
testOk1(!three.unique());
|
||||
|
||||
testOk1(two.data() == three.data());
|
||||
|
||||
one = two;
|
||||
|
||||
testOk1(!one.unique());
|
||||
|
||||
testOk1(two.data() == one.data());
|
||||
|
||||
one = one; // no-op
|
||||
|
||||
testOk1(two.data() == one.data());
|
||||
|
||||
one[1] = 43;
|
||||
testOk1(two[1]==43);
|
||||
testOk1(three[1]==43);
|
||||
|
||||
one.make_unique();
|
||||
|
||||
testOk1(one[1]==43);
|
||||
one[1] = 143;
|
||||
testOk1(two[1]==43);
|
||||
testOk1(three[1]==43);
|
||||
|
||||
two.resize(two.size());
|
||||
|
||||
testOk1(two[1]==43);
|
||||
two[1] = 243;
|
||||
testOk1(one[1]==143);
|
||||
testOk1(three[1]==43);
|
||||
|
||||
testOk1(one.unique());
|
||||
testOk1(two.unique());
|
||||
testOk1(three.unique());
|
||||
|
||||
one.resize(2);
|
||||
|
||||
testOk1(one.size()==2);
|
||||
testOk1(one[1]==143);
|
||||
testOk1(two.size()==15);
|
||||
testOk1(three.size()==15);
|
||||
|
||||
two.resize(20, 5000);
|
||||
|
||||
testOk1(two[1]==243);
|
||||
testOk1(one.size()==2);
|
||||
testOk1(two.size()==20);
|
||||
testOk1(three.size()==15);
|
||||
|
||||
testOk1(two[19]==5000);
|
||||
}
|
||||
|
||||
static void testConst()
|
||||
{
|
||||
testDiag("Test constant vector");
|
||||
|
||||
epics::pvData::shared_vector<int> writable(15, 100);
|
||||
|
||||
epics::pvData::shared_vector<int>::reference wr = writable[0];
|
||||
epics::pvData::shared_vector<int>::const_reference ror = writable[0];
|
||||
|
||||
testOk1(wr==ror);
|
||||
|
||||
int *compare = writable.data();
|
||||
|
||||
testOk1(writable.unique());
|
||||
|
||||
// can re-target container, but data is R/O
|
||||
epics::pvData::shared_vector<const int> rodata(freeze(writable));
|
||||
|
||||
epics::pvData::shared_vector<const int>::reference wcr = rodata[0];
|
||||
epics::pvData::shared_vector<const int>::const_reference rocr = rodata[0];
|
||||
|
||||
testOk1(wcr==rocr);
|
||||
|
||||
testOk1(rodata.data()==compare);
|
||||
writable = thaw(rodata);
|
||||
|
||||
testOk1(writable.data()==compare);
|
||||
|
||||
rodata = freeze(writable);
|
||||
|
||||
testOk1(rodata.data()==compare);
|
||||
|
||||
epics::pvData::shared_vector<const int> rodata2(rodata);
|
||||
|
||||
testOk1(rodata.data()==rodata2.data());
|
||||
|
||||
rodata2.make_unique();
|
||||
|
||||
testOk1(rodata.data()!=rodata2.data());
|
||||
}
|
||||
|
||||
static void testSlice()
|
||||
{
|
||||
testDiag("Test vector slicing");
|
||||
|
||||
epics::pvData::shared_vector<int> original(10, 100);
|
||||
|
||||
epics::pvData::shared_vector<int> half1(original), half2(original), half2a(original);
|
||||
|
||||
half1.slice(0, 5);
|
||||
half2.slice(5, 5);
|
||||
half2a.slice(5);
|
||||
|
||||
testOk1(half1.dataOffset()==0);
|
||||
testOk1(half2.dataOffset()==5);
|
||||
testOk1(half2a.dataOffset()==5);
|
||||
|
||||
testOk1(half1.size()==5);
|
||||
testOk1(half2.size()==5);
|
||||
testOk1(half2a.size()==5);
|
||||
|
||||
testOk1(half1.dataTotal()==10);
|
||||
testOk1(half2.dataTotal()==5);
|
||||
testOk1(half2a.dataTotal()==5);
|
||||
|
||||
testOk1(original.data() == half1.data());
|
||||
testOk1(half2.data() == half2a.data());
|
||||
|
||||
half1.slice(100000);
|
||||
half2.slice(1);
|
||||
half2a.slice(1,1);
|
||||
|
||||
testOk1(half1.dataOffset()==5);
|
||||
testOk1(half2.dataOffset()==6);
|
||||
testOk1(half2a.dataOffset()==6);
|
||||
|
||||
testOk1(half1.size()==0);
|
||||
testOk1(half2.size()==4);
|
||||
testOk1(half2a.size()==1);
|
||||
|
||||
testOk1(half1.dataTotal()==5);
|
||||
testOk1(half2.dataTotal()==4);
|
||||
testOk1(half2a.dataTotal()==4);
|
||||
|
||||
half2.clear();
|
||||
testOk1(half2.dataOffset()==0);
|
||||
testOk1(half2.dataCount()==0);
|
||||
testOk1(half2.dataTotal()==0);
|
||||
testOk1(half2.data()==NULL);
|
||||
}
|
||||
|
||||
static void testCapacity()
|
||||
{
|
||||
testDiag("Test vector capacity");
|
||||
|
||||
epics::pvData::shared_vector<int> vect(10, 100);
|
||||
|
||||
int *peek = vect.dataPtr().get();
|
||||
|
||||
vect.slice(0, 5);
|
||||
|
||||
testOk1(vect.size()==5);
|
||||
testOk1(vect.dataTotal()==10);
|
||||
testOk1(vect.dataPtr().get() == peek);
|
||||
|
||||
vect.resize(6);
|
||||
|
||||
testOk1(vect.dataPtr().get() == peek);
|
||||
testOk1(vect.size()==6);
|
||||
testOk1(vect.dataTotal()==10);
|
||||
|
||||
vect.resize(10);
|
||||
|
||||
testOk1(vect.dataPtr().get() == peek);
|
||||
testOk1(vect.size()==10);
|
||||
testOk1(vect.dataTotal()==10);
|
||||
|
||||
vect.resize(11);
|
||||
|
||||
testOk1(vect.dataPtr().get() != peek);
|
||||
testOk1(vect.size()==11);
|
||||
testOk1(vect.dataTotal()>=11);
|
||||
|
||||
vect[1] = 124;
|
||||
|
||||
vect.reserve(15);
|
||||
|
||||
testOk1(vect.size()==11);
|
||||
testOk1(vect.dataTotal()>=15);
|
||||
|
||||
testOk1(vect[1]==124);
|
||||
}
|
||||
|
||||
static void testPush()
|
||||
{
|
||||
epics::pvData::shared_vector<int> vect;
|
||||
|
||||
testDiag("Test push_back optimizations");
|
||||
|
||||
size_t nallocs = 0;
|
||||
size_t cap = vect.capacity();
|
||||
|
||||
for(size_t s=0; s<16*1024; s++) {
|
||||
vect.push_back(s);
|
||||
|
||||
if(cap!=vect.capacity()) {
|
||||
nallocs++;
|
||||
cap = vect.capacity();
|
||||
}
|
||||
}
|
||||
|
||||
testDiag("push_back %ld times caused %ld re-allocations",
|
||||
(unsigned long)vect.size(),
|
||||
(unsigned long)nallocs);
|
||||
|
||||
testOk1(nallocs==26);
|
||||
}
|
||||
|
||||
static void testVoid()
|
||||
{
|
||||
testDiag("Test vecter cast to/from void");
|
||||
|
||||
epics::pvData::shared_vector<int> typed(4);
|
||||
|
||||
epics::pvData::shared_vector<void> untyped2(epics::pvData::static_shared_vector_cast<void>(typed));
|
||||
|
||||
testOk1(typed.dataPtr().get()==untyped2.dataPtr().get());
|
||||
testOk1(typed.size()*sizeof(int)==untyped2.size());
|
||||
|
||||
untyped2.slice(sizeof(int), 2*sizeof(int));
|
||||
|
||||
typed = epics::pvData::static_shared_vector_cast<int>(untyped2);
|
||||
|
||||
testOk1(typed.dataOffset()==1);
|
||||
testOk1(typed.size()==2);
|
||||
}
|
||||
|
||||
struct dummyStruct {};
|
||||
|
||||
static void testNonPOD()
|
||||
{
|
||||
testDiag("Test vector of non-POD types");
|
||||
|
||||
epics::pvData::shared_vector<std::string> strings(6);
|
||||
epics::pvData::shared_vector<std::tr1::shared_ptr<dummyStruct> > structs(5);
|
||||
|
||||
testOk1(strings[0].empty());
|
||||
testOk1(structs[0].get()==NULL);
|
||||
|
||||
structs[1].reset(new dummyStruct);
|
||||
dummyStruct *temp = structs[1].get();
|
||||
|
||||
epics::pvData::shared_vector<std::tr1::shared_ptr<dummyStruct> > structs2(structs);
|
||||
|
||||
testOk1(!structs.unique());
|
||||
testOk1(structs[1].unique());
|
||||
|
||||
testOk1(structs2[1].get()==temp);
|
||||
|
||||
structs2.make_unique();
|
||||
|
||||
testOk1(structs.unique());
|
||||
testOk1(!structs[1].unique());
|
||||
|
||||
testOk1(structs2[1].get()==temp);
|
||||
}
|
||||
|
||||
static void testVectorConvert()
|
||||
{
|
||||
testDiag("Test shared_vector_convert");
|
||||
|
||||
epics::pvData::shared_vector<int> ints(6, 42), moreints;
|
||||
epics::pvData::shared_vector<float> floats;
|
||||
epics::pvData::shared_vector<std::string> strings;
|
||||
epics::pvData::shared_vector<void> voids;
|
||||
|
||||
testOk1(ints.unique());
|
||||
|
||||
// no-op convert. Just returns another reference
|
||||
moreints = epics::pvData::shared_vector_convert<int>(ints);
|
||||
|
||||
testOk1(!ints.unique());
|
||||
moreints.clear();
|
||||
|
||||
// conversion when both types are known.
|
||||
// returns a new vector
|
||||
floats = epics::pvData::shared_vector_convert<float>(ints);
|
||||
|
||||
testOk1(ints.unique());
|
||||
testOk1(floats.size()==ints.size());
|
||||
testOk1(floats.at(0)==42.0);
|
||||
|
||||
// convert to void is static_shared_vector_cast<void>()
|
||||
// returns a reference
|
||||
voids = epics::pvData::shared_vector_convert<void>(ints);
|
||||
|
||||
testOk1(!ints.unique());
|
||||
testOk1(voids.size()==ints.size()*sizeof(int));
|
||||
|
||||
// convert from void uses shared_vector<void>::original_type()
|
||||
// to find that the actual type is 'int'.
|
||||
// returns a new vector
|
||||
strings = epics::pvData::shared_vector_convert<std::string>(voids);
|
||||
|
||||
voids.clear();
|
||||
|
||||
testOk1(ints.unique());
|
||||
testOk1(strings.size()==ints.size());
|
||||
testOk1(strings.at(0)=="42");
|
||||
}
|
||||
|
||||
static void testWeak()
|
||||
{
|
||||
testDiag("Test weak_ptr counting");
|
||||
|
||||
epics::pvData::shared_vector<int> data(6);
|
||||
|
||||
testOk1(data.unique());
|
||||
|
||||
std::tr1::shared_ptr<int> pdata(data.dataPtr());
|
||||
|
||||
testOk1(!data.unique());
|
||||
|
||||
pdata.reset();
|
||||
|
||||
testOk1(data.unique());
|
||||
|
||||
std::tr1::weak_ptr<int> wdata(data.dataPtr());
|
||||
|
||||
testOk1(data.unique()); // True, but I wish it wasn't!!!
|
||||
|
||||
pdata = wdata.lock();
|
||||
|
||||
testOk1(!data.unique());
|
||||
}
|
||||
|
||||
static void testICE()
|
||||
{
|
||||
testDiag("Test freeze and thaw");
|
||||
|
||||
epics::pvData::shared_vector<int> A(6, 42), C;
|
||||
epics::pvData::shared_vector<const int> B, D;
|
||||
|
||||
int *check = A.data();
|
||||
|
||||
// check freeze w/ unique reference
|
||||
|
||||
// clears A and moves reference to B
|
||||
// no copy
|
||||
B = epics::pvData::freeze(A);
|
||||
|
||||
testOk1(A.unique());
|
||||
testOk1(B.unique());
|
||||
testOk1(A.size()==0);
|
||||
testOk1(B.size()==6);
|
||||
testOk1(A.data()!=check);
|
||||
testOk1(B.data()==check);
|
||||
|
||||
D = B; // create second const reference
|
||||
|
||||
// clears D, but reference to B refrence
|
||||
// to B remains, so a copy is made
|
||||
C = epics::pvData::thaw(D);
|
||||
|
||||
testOk1(B.unique());
|
||||
testOk1(C.unique());
|
||||
testOk1(B.size()==6);
|
||||
testOk1(C.size()==6);
|
||||
testOk1(B.data()==check);
|
||||
testOk1(C.data()!=NULL);
|
||||
testOk1(C.at(0)==42);
|
||||
|
||||
C.clear();
|
||||
|
||||
// clears B and moves reference to A
|
||||
// no copy
|
||||
A = epics::pvData::thaw(B);
|
||||
|
||||
testOk1(A.unique());
|
||||
testOk1(B.unique());
|
||||
testOk1(A.size()==6);
|
||||
testOk1(B.size()==0);
|
||||
testOk1(A.data()==check);
|
||||
testOk1(B.data()!=check);
|
||||
|
||||
C = A; // create second non-const reference
|
||||
|
||||
testOk1(!A.unique());
|
||||
|
||||
try {
|
||||
// would clear A, but remaining reference C
|
||||
// fails operation. A not cleared
|
||||
// and exception thrown
|
||||
B = epics::pvData::freeze(A);
|
||||
testFail("Froze non-unique vector!");
|
||||
} catch(std::runtime_error& e) {
|
||||
testPass("freeze of non-unique throws runtime_error as expected");
|
||||
}
|
||||
}
|
||||
|
||||
MAIN(testSharedVector)
|
||||
{
|
||||
testPlan(162);
|
||||
testDiag("Tests for shared_vector");
|
||||
|
||||
testDiag("sizeof(shared_vector<int>)=%lu",
|
||||
(unsigned long)sizeof(epics::pvData::shared_vector<int>));
|
||||
|
||||
testEmpty();
|
||||
testInternalAlloc();
|
||||
testExternalAlloc();
|
||||
testCapacity();
|
||||
testShare();
|
||||
testConst();
|
||||
testSlice();
|
||||
testPush();
|
||||
testVoid();
|
||||
testNonPOD();
|
||||
testVectorConvert();
|
||||
testWeak();
|
||||
testICE();
|
||||
return testDone();
|
||||
}
|
||||
@@ -0,0 +1,407 @@
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/* Author: Michael Davidsaver */
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <typeinfo>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <float.h>
|
||||
#include <epicsMath.h>
|
||||
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include "pv/typeCast.h"
|
||||
|
||||
using epics::pvData::String;
|
||||
|
||||
namespace {
|
||||
|
||||
template<typename T>
|
||||
struct testequal {
|
||||
static bool op(T A, T B) {return A==B; }
|
||||
};
|
||||
template<>
|
||||
struct testequal<double> {
|
||||
static bool op(double A, double B) {return fabs(A-B)<1e-300; }
|
||||
};
|
||||
template<>
|
||||
struct testequal<float> {
|
||||
static bool op(float A, float B) {return fabs(A-B)<1e-30; }
|
||||
};
|
||||
|
||||
template<typename TO, typename FROM>
|
||||
struct testcase {
|
||||
static void op(TO expect, FROM inp)
|
||||
{
|
||||
std::ostringstream msg;
|
||||
TO actual;
|
||||
try {
|
||||
actual = ::epics::pvData::castUnsafe<TO,FROM>(inp);
|
||||
//actual = ::epics::pvData::detail::cast_helper<TO,FROM>::op(inp);
|
||||
} catch(std::runtime_error& e) {
|
||||
msg<<"Failed to cast "
|
||||
<<inp<<" ("<<typeid(FROM).name()<<") -> "
|
||||
<<expect<<" ("<<typeid(TO).name()<<")\n Error: "
|
||||
<<typeid(e).name()<<"("<<e.what()<<")";
|
||||
testFail("%s", msg.str().c_str());
|
||||
return;
|
||||
}
|
||||
if(!testequal<TO>::op(actual, expect)) {
|
||||
msg<<"Failed cast gives unexpected value "
|
||||
<<inp<<" ("<<typeid(FROM).name()<<") -> "
|
||||
<<expect<<" ("<<typeid(TO).name()<<") yields: "
|
||||
<<actual;
|
||||
testFail("%s", msg.str().c_str());
|
||||
return;
|
||||
}
|
||||
msg<<"cast "
|
||||
<<inp<<" ("<<typeid(FROM).name()<<") -> "
|
||||
<<expect<<" ("<<typeid(TO).name()<<") yields: "
|
||||
<<actual;
|
||||
testPass("%s", msg.str().c_str());
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename TO, typename FROM>
|
||||
struct testfail {
|
||||
static void op(FROM inp)
|
||||
{
|
||||
std::ostringstream msg;
|
||||
TO actual;
|
||||
try {
|
||||
actual = ::epics::pvData::castUnsafe<TO,FROM>(inp);
|
||||
msg<<"Failed to generate expected error "
|
||||
<<inp<<" ("<<typeid(FROM).name()<<") -> ("
|
||||
<<typeid(TO).name()<<") yields: "
|
||||
<<actual;
|
||||
testFail("%s", msg.str().c_str());
|
||||
return;
|
||||
} catch(std::runtime_error& e) {
|
||||
msg<<"Got expected error "
|
||||
<<inp<<" ("<<typeid(FROM).name()<<") -> ("
|
||||
<<typeid(TO).name()<<") fails with: "
|
||||
<<e.what();
|
||||
testPass("%s", msg.str().c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Test cast
|
||||
#define TEST(TTO, VTO, TFRO, VFRO) testcase<TTO, TFRO>::op(VTO, VFRO)
|
||||
|
||||
// Test cast and reverse
|
||||
#define TEST2(TTO, VTO, TFRO, VFRO) TEST(TTO, VTO, TFRO, VFRO); TEST(TFRO, VFRO, TTO, VTO)
|
||||
|
||||
#define FAIL(TTO, TFRO, VFRO) testfail<TTO,TFRO>::op(VFRO)
|
||||
|
||||
} // end namespace
|
||||
|
||||
|
||||
MAIN(testTypeCast)
|
||||
{
|
||||
testPlan(110);
|
||||
|
||||
try {
|
||||
|
||||
int8_t xint8=0;
|
||||
uint8_t xuint8=0;
|
||||
int16_t xint16=0;
|
||||
uint16_t xuint16=0;
|
||||
int32_t xint32=0;
|
||||
uint32_t xuint32=0;
|
||||
int64_t xint64=0;
|
||||
uint64_t xuint64=0;
|
||||
float xfloat=0.0;
|
||||
double xdouble=0.0;
|
||||
epics::pvData::String xString("0");
|
||||
|
||||
typedef float float_t;
|
||||
typedef double double_t;
|
||||
typedef epics::pvData::String String_t;
|
||||
|
||||
// force all possibilities to be compiled
|
||||
#define CHECK(M, N) x## M = ::epics::pvData::castUnsafe<M ##_t>(x## N); \
|
||||
std::transform(&x ## N, &x ## N+1, &x ## M, ::epics::pvData::castUnsafe<M ##_t,N ##_t>)
|
||||
//#define CHECK(M, N) x## M = ::epics::pvData::detail::cast_helper<M ##_t,N ##_t>::op(x## N)
|
||||
CHECK(int8, int8);
|
||||
CHECK(int8, uint8);
|
||||
CHECK(int8, int16);
|
||||
CHECK(int8, uint16);
|
||||
CHECK(int8, int32);
|
||||
CHECK(int8, uint32);
|
||||
CHECK(int8, int64);
|
||||
CHECK(int8, uint64);
|
||||
CHECK(int8, float);
|
||||
CHECK(int8, double);
|
||||
CHECK(int8, String);
|
||||
|
||||
CHECK(uint8, int8);
|
||||
CHECK(uint8, uint8);
|
||||
CHECK(uint8, int16);
|
||||
CHECK(uint8, uint16);
|
||||
CHECK(uint8, int32);
|
||||
CHECK(uint8, uint32);
|
||||
CHECK(uint8, int64);
|
||||
CHECK(uint8, uint64);
|
||||
CHECK(uint8, float);
|
||||
CHECK(uint8, double);
|
||||
CHECK(uint8, String);
|
||||
|
||||
CHECK(int16, int8);
|
||||
CHECK(int16, uint8);
|
||||
CHECK(int16, int16);
|
||||
CHECK(int16, uint16);
|
||||
CHECK(int16, int32);
|
||||
CHECK(int16, uint32);
|
||||
CHECK(int16, int64);
|
||||
CHECK(int16, uint64);
|
||||
CHECK(int16, float);
|
||||
CHECK(int16, double);
|
||||
CHECK(int16, String);
|
||||
|
||||
CHECK(uint16, int8);
|
||||
CHECK(uint16, uint8);
|
||||
CHECK(uint16, int16);
|
||||
CHECK(uint16, uint16);
|
||||
CHECK(uint16, int32);
|
||||
CHECK(uint16, uint32);
|
||||
CHECK(uint16, int64);
|
||||
CHECK(uint16, uint64);
|
||||
CHECK(uint16, float);
|
||||
CHECK(uint16, double);
|
||||
CHECK(uint16, String);
|
||||
|
||||
CHECK(int32, int8);
|
||||
CHECK(int32, uint8);
|
||||
CHECK(int32, int16);
|
||||
CHECK(int32, uint16);
|
||||
CHECK(int32, int32);
|
||||
CHECK(int32, uint32);
|
||||
CHECK(int32, int64);
|
||||
CHECK(int32, uint64);
|
||||
CHECK(int32, float);
|
||||
CHECK(int32, double);
|
||||
CHECK(int32, String);
|
||||
|
||||
CHECK(uint32, int8);
|
||||
CHECK(uint32, uint8);
|
||||
CHECK(uint32, int16);
|
||||
CHECK(uint32, uint16);
|
||||
CHECK(uint32, int32);
|
||||
CHECK(uint32, uint32);
|
||||
CHECK(uint32, int64);
|
||||
CHECK(uint32, uint64);
|
||||
CHECK(uint32, float);
|
||||
CHECK(uint32, double);
|
||||
CHECK(uint32, String);
|
||||
|
||||
CHECK(int64, int8);
|
||||
CHECK(int64, uint8);
|
||||
CHECK(int64, int16);
|
||||
CHECK(int64, uint16);
|
||||
CHECK(int64, int32);
|
||||
CHECK(int64, uint32);
|
||||
CHECK(int64, int64);
|
||||
CHECK(int64, uint64);
|
||||
CHECK(int64, float);
|
||||
CHECK(int64, double);
|
||||
//CHECK(int64, String);
|
||||
|
||||
CHECK(uint64, int8);
|
||||
CHECK(uint64, uint8);
|
||||
CHECK(uint64, int16);
|
||||
CHECK(uint64, uint16);
|
||||
CHECK(uint64, int32);
|
||||
CHECK(uint64, uint32);
|
||||
CHECK(uint64, int64);
|
||||
CHECK(uint64, uint64);
|
||||
CHECK(uint64, float);
|
||||
CHECK(uint64, double);
|
||||
//CHECK(uint64, String);
|
||||
|
||||
CHECK(float, int8);
|
||||
CHECK(float, uint8);
|
||||
CHECK(float, int16);
|
||||
CHECK(float, uint16);
|
||||
CHECK(float, int32);
|
||||
CHECK(float, uint32);
|
||||
CHECK(float, int64);
|
||||
CHECK(float, uint64);
|
||||
CHECK(float, float);
|
||||
CHECK(float, double);
|
||||
CHECK(float, String);
|
||||
|
||||
CHECK(double, int8);
|
||||
CHECK(double, uint8);
|
||||
CHECK(double, int16);
|
||||
CHECK(double, uint16);
|
||||
CHECK(double, int32);
|
||||
CHECK(double, uint32);
|
||||
CHECK(double, int64);
|
||||
CHECK(double, uint64);
|
||||
CHECK(double, float);
|
||||
CHECK(double, double);
|
||||
CHECK(double, String);
|
||||
|
||||
CHECK(String, int8);
|
||||
CHECK(String, uint8);
|
||||
CHECK(String, int16);
|
||||
CHECK(String, uint16);
|
||||
CHECK(String, int32);
|
||||
CHECK(String, uint32);
|
||||
CHECK(String, int64);
|
||||
CHECK(String, uint64);
|
||||
CHECK(String, float);
|
||||
CHECK(String, double);
|
||||
CHECK(String, String);
|
||||
#undef CHECK
|
||||
|
||||
testDiag("Integer signed <=> unsigned");
|
||||
|
||||
TEST2(uint8_t, std::numeric_limits<uint8_t>::max(), int8_t, -1);
|
||||
TEST2(uint16_t, std::numeric_limits<uint16_t>::max(), int8_t, -1);
|
||||
TEST2(uint32_t, std::numeric_limits<uint32_t>::max(), int8_t, -1);
|
||||
TEST2(uint64_t, std::numeric_limits<uint64_t>::max(), int8_t, -1);
|
||||
|
||||
testDiag("Integer unsigned promote (and demote when in range)");
|
||||
|
||||
TEST2(uint16_t, 0xff, uint8_t, 0xff);
|
||||
TEST2(uint32_t, 0xffff, uint16_t, 0xffff);
|
||||
TEST2(uint64_t, 0xffffffffu, uint32_t, 0xffffffffu);
|
||||
|
||||
TEST2(int16_t, 0x7f, int8_t, 0x7f);
|
||||
TEST2(int32_t, 0x7fff, int16_t, 0x7fff);
|
||||
TEST2(int64_t, 0x7fffffff, int32_t, 0x7fffffff);
|
||||
|
||||
testDiag("Double to int w/ round towards zero (aka truncation)");
|
||||
|
||||
TEST(int32_t, 2, double, 2.1);
|
||||
TEST(int32_t, 2, double, 2.5);
|
||||
TEST(int32_t, 2, double, 2.7);
|
||||
TEST(int32_t, -2, double, -2.1);
|
||||
TEST(int32_t, -2, double, -2.5);
|
||||
TEST(int32_t, -2, double, -2.7);
|
||||
|
||||
testDiag("Float to int w/ round towards zero (aka truncation)");
|
||||
|
||||
TEST(int32_t, 2, float, 2.1);
|
||||
TEST(int32_t, 2, float, 2.5);
|
||||
TEST(int32_t, 2, float, 2.7);
|
||||
TEST(int32_t, -2, float, -2.1);
|
||||
TEST(int32_t, -2, float, -2.5);
|
||||
TEST(int32_t, -2, float, -2.7);
|
||||
|
||||
testDiag("String Printing/parsing");
|
||||
|
||||
TEST2(String, "1", int32_t, 1);
|
||||
TEST2(String, "-1", int32_t, -1);
|
||||
TEST2(String, "1", int8_t, 1);
|
||||
TEST2(String, "-1", int8_t, -1);
|
||||
TEST2(String, "1", uint8_t, 1);
|
||||
TEST2(String, "-1", char, -1);
|
||||
|
||||
TEST2(String, "127", int32_t, std::numeric_limits<int8_t>::max());
|
||||
TEST2(String, "-128", int32_t, std::numeric_limits<int8_t>::min());
|
||||
TEST2(String, "255", int32_t, std::numeric_limits<uint8_t>::max());
|
||||
|
||||
TEST2(String, "32767", int32_t, std::numeric_limits<int16_t>::max());
|
||||
TEST2(String, "-32768", int32_t, std::numeric_limits<int16_t>::min());
|
||||
TEST2(String, "65535", int32_t, std::numeric_limits<uint16_t>::max());
|
||||
|
||||
TEST2(String, "2147483647", int32_t, std::numeric_limits<int32_t>::max());
|
||||
TEST2(String, "-2147483648", int32_t, std::numeric_limits<int32_t>::min());
|
||||
TEST2(String, "4294967295", uint32_t, std::numeric_limits<uint32_t>::max());
|
||||
|
||||
TEST2(String, "9223372036854775807", int64_t, std::numeric_limits<int64_t>::max());
|
||||
TEST2(String, "-9223372036854775808", int64_t, std::numeric_limits<int64_t>::min());
|
||||
TEST2(String, "18446744073709551615", uint64_t, std::numeric_limits<uint64_t>::max());
|
||||
|
||||
TEST2(String, "1.1", double, 1.1);
|
||||
TEST2(String, "1.1e+100", double, 1.1e100);
|
||||
TEST2(String, "1.1e-100", double, 1.1e-100);
|
||||
|
||||
TEST(double, 1.1e100, String, "1.1E+100");
|
||||
|
||||
testDiag("String Parsing");
|
||||
|
||||
TEST(int32_t, 15, String, "0xf");
|
||||
TEST(int32_t, 15, String, "0xF");
|
||||
TEST(int32_t, -15, String, "-0xF");
|
||||
TEST(int32_t, 16, String, "0x10");
|
||||
TEST(int32_t, -16, String, "-0x10");
|
||||
|
||||
TEST(int32_t, 7, String, "07");
|
||||
TEST(int32_t, 8, String, "010");
|
||||
TEST(int32_t, -7, String, "-07");
|
||||
TEST(int32_t, -8, String, "-010");
|
||||
|
||||
TEST(int64_t, 15, String, "0xf");
|
||||
TEST(int64_t, 15, String, "0xF");
|
||||
TEST(int64_t, -15, String, "-0xF");
|
||||
TEST(int64_t, 16, String, "0x10");
|
||||
TEST(int64_t, -16, String, "-0x10");
|
||||
|
||||
TEST(int64_t, 7, String, "07");
|
||||
TEST(int64_t, 8, String, "010");
|
||||
TEST(int64_t, -7, String, "-07");
|
||||
TEST(int64_t, -8, String, "-010");
|
||||
|
||||
testDiag("String parsing errors");
|
||||
|
||||
FAIL(int32_t, String, "hello!");
|
||||
FAIL(int32_t, String, "42 is the answer");
|
||||
FAIL(int64_t, String, "hello!");
|
||||
FAIL(int64_t, String, "42 is the answer");
|
||||
FAIL(double, String, "hello!");
|
||||
FAIL(double, String, "42 is the answer");
|
||||
|
||||
FAIL(int8_t, String, "1000");
|
||||
FAIL(int8_t, String, "-1000");
|
||||
;
|
||||
FAIL(double, String, "1e+10000000");
|
||||
|
||||
testDiag("Floating point overflows");
|
||||
|
||||
TEST(float, FLT_MAX, double, 1e300);
|
||||
TEST(float, -FLT_MAX, double, -1e300);
|
||||
TEST(float, FLT_MIN, double, 1e-300);
|
||||
TEST(float, -FLT_MIN, double, -1e-300);
|
||||
|
||||
xfloat = ::epics::pvData::castUnsafe<float,double>(epicsNAN);
|
||||
testOk(isnan( xfloat ), "Test cast double NAN to float NAN yields: %f", xfloat);
|
||||
|
||||
{
|
||||
std::string result[3];
|
||||
const int32_t in[3] = { 1234, 506001, 42424242 };
|
||||
|
||||
testDiag("Test vcast int32 -> String");
|
||||
epics::pvData::castUnsafeV(3, epics::pvData::pvString, (void*)result,
|
||||
epics::pvData::pvInt, (void*)in);
|
||||
testDiag("Yields %s %s %s", result[0].c_str(), result[1].c_str(), result[2].c_str());
|
||||
|
||||
testOk1(result[0]=="1234");
|
||||
testOk1(result[1]=="506001");
|
||||
testOk1(result[2]=="42424242");
|
||||
}
|
||||
|
||||
} catch(std::exception& e) {
|
||||
testAbort("Uncaught exception: %s", e.what());
|
||||
}
|
||||
|
||||
return testDone();
|
||||
}
|
||||
@@ -229,11 +229,11 @@ static void testEnumerated(FILE * fd,FILE */*auxfd*/)
|
||||
assert(result);
|
||||
int32 index = pvEnumerated.getIndex();
|
||||
String choice = pvEnumerated.getChoice();
|
||||
StringArrayPtr const & choices = pvEnumerated.getChoices();
|
||||
PVStringArray::const_svector choices = pvEnumerated.getChoices();
|
||||
int32 numChoices = pvEnumerated.getNumberChoices();
|
||||
if(debug) {
|
||||
fprintf(fd,"index %d choice %s choices",index,choice.c_str());
|
||||
for(int i=0; i<numChoices; i++ ) fprintf(fd," %s",(*choices)[i].c_str());
|
||||
for(int i=0; i<numChoices; i++ ) fprintf(fd," %s",choices[i].c_str());
|
||||
fprintf(fd,"\n");
|
||||
}
|
||||
pvEnumerated.setIndex(2);
|
||||
|
||||
+6
-1
@@ -9,6 +9,7 @@ testBitSetUtil_LIBS += pvData Com
|
||||
PROD_HOST += testIntrospect
|
||||
testIntrospect_SRCS += testIntrospect.cpp
|
||||
testIntrospect_LIBS += pvData Com
|
||||
TESTS += testIntrospect
|
||||
|
||||
PROD_HOST += testPVAppend
|
||||
testPVAppend_SRCS += testPVAppend.cpp
|
||||
@@ -38,18 +39,22 @@ PROD_HOST += testConvert
|
||||
testConvert_SRCS += testConvert.cpp
|
||||
testConvert_LIBS += pvData Com
|
||||
|
||||
PROD_HOST += testPVScalarArray
|
||||
TESTPROD += testPVScalarArray
|
||||
testPVScalarArray_SRCS += testPVScalarArray.cpp
|
||||
testPVScalarArray_LIBS += pvData Com
|
||||
TESTS += testPVScalarArray
|
||||
|
||||
PROD_HOST += testPVStructureArray
|
||||
testPVStructureArray_SRCS += testPVStructureArray.cpp
|
||||
testPVStructureArray_LIBS += pvData Com
|
||||
TESTS += testPVStructureArray
|
||||
|
||||
PROD_HOST += testOperators
|
||||
testOperators_SRCS += testOperators.cpp
|
||||
testOperators_LIBS += pvData Com
|
||||
|
||||
TESTSCRIPTS_HOST += $(TESTS:%=%.t)
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
#----------------------------------------
|
||||
# ADD RULES AFTER THIS LINE
|
||||
|
||||
+37
-743
@@ -14,6 +14,8 @@
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsExit.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/requester.h>
|
||||
#include <pv/pvIntrospect.h>
|
||||
@@ -23,750 +25,42 @@
|
||||
#include <pv/standardPVField.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
using std::tr1::static_pointer_cast;
|
||||
|
||||
static bool debug = false;
|
||||
|
||||
static FieldCreatePtr fieldCreate;
|
||||
static PVDataCreatePtr pvDataCreate;
|
||||
static StandardFieldPtr standardField;
|
||||
static StandardPVFieldPtr standardPVField;
|
||||
static ConvertPtr convert;
|
||||
static String builder("");
|
||||
|
||||
static void testConvertScalar(FILE *fd) {
|
||||
PVScalarPtr pvBytePtr = pvDataCreate->createPVScalar(pvByte);
|
||||
PVScalarPtr pvUBytePtr = pvDataCreate->createPVScalar(pvUByte);
|
||||
PVScalarPtr pvShortPtr = pvDataCreate->createPVScalar(pvShort);
|
||||
PVScalarPtr pvUShortPtr = pvDataCreate->createPVScalar(pvUShort);
|
||||
PVScalarPtr pvIntPtr = pvDataCreate->createPVScalar(pvInt);
|
||||
PVScalarPtr pvUIntPtr = pvDataCreate->createPVScalar(pvUInt);
|
||||
PVScalarPtr pvLongPtr = pvDataCreate->createPVScalar(pvLong);
|
||||
PVScalarPtr pvULongPtr = pvDataCreate->createPVScalar(pvULong);
|
||||
PVScalarPtr pvFloatPtr = pvDataCreate->createPVScalar(pvFloat);
|
||||
PVScalarPtr pvDoublePtr = pvDataCreate->createPVScalar(pvDouble);
|
||||
|
||||
fprintf(fd,"testConvertScalar\n");
|
||||
if(debug) fprintf(fd,"\nfromByte\n");
|
||||
int8 bval = 127;
|
||||
for(int i=0; i<3; i++) {
|
||||
convert->fromByte(pvBytePtr, bval);
|
||||
builder.clear(); pvBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"byte %s\n",builder.c_str());
|
||||
convert->fromByte(pvUBytePtr, bval);
|
||||
builder.clear(); pvUBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
|
||||
convert->fromByte(pvShortPtr, bval);
|
||||
builder.clear(); pvShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"short %s\n",builder.c_str());
|
||||
convert->fromByte(pvUShortPtr, bval);
|
||||
builder.clear(); pvUShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
|
||||
convert->fromByte(pvIntPtr, bval);
|
||||
builder.clear(); pvIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"int %s\n",builder.c_str());
|
||||
convert->fromByte(pvUIntPtr, bval);
|
||||
builder.clear(); pvUIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"uint %s\n",builder.c_str());
|
||||
convert->fromByte(pvLongPtr, bval);
|
||||
builder.clear(); pvLongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"long %s\n",builder.c_str());
|
||||
convert->fromByte(pvULongPtr, bval);
|
||||
builder.clear(); pvULongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
|
||||
convert->fromByte(pvFloatPtr, bval);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float %s\n",builder.c_str());
|
||||
convert->fromByte(pvDoublePtr, bval);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double %s\n",builder.c_str());
|
||||
convert->copyScalar(pvUBytePtr, pvFloatPtr);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
|
||||
convert->copyScalar(pvUBytePtr, pvDoublePtr);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
|
||||
bval++;
|
||||
}
|
||||
fprintf(fd,"fromByte PASSED\n");
|
||||
|
||||
if(debug) fprintf(fd,"\nfromShort\n");
|
||||
int16 sval = 0x7fff;
|
||||
for(int i=0; i<3; i++) {
|
||||
convert->fromShort(pvBytePtr, sval);
|
||||
builder.clear(); pvBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"byte %s\n",builder.c_str());
|
||||
convert->fromShort(pvUBytePtr, sval);
|
||||
builder.clear(); pvUBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
|
||||
convert->fromShort(pvShortPtr, sval);
|
||||
builder.clear(); pvShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"short %s\n",builder.c_str());
|
||||
convert->fromShort(pvUShortPtr, sval);
|
||||
builder.clear(); pvUShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
|
||||
convert->fromShort(pvIntPtr, sval);
|
||||
builder.clear(); pvIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"int %s\n",builder.c_str());
|
||||
convert->fromShort(pvUIntPtr, sval);
|
||||
builder.clear(); pvUIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"uint %s\n",builder.c_str());
|
||||
convert->fromShort(pvLongPtr, sval);
|
||||
builder.clear(); pvLongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"long %s\n",builder.c_str());
|
||||
convert->fromShort(pvULongPtr, sval);
|
||||
builder.clear(); pvULongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
|
||||
convert->fromShort(pvFloatPtr, sval);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float %s\n",builder.c_str());
|
||||
convert->fromShort(pvDoublePtr, sval);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double %s\n",builder.c_str());
|
||||
convert->copyScalar(pvUShortPtr, pvFloatPtr);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
|
||||
convert->copyScalar(pvUShortPtr, pvDoublePtr);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
|
||||
sval++;
|
||||
}
|
||||
fprintf(fd,"fromShort PASSED\n");
|
||||
|
||||
if(debug) fprintf(fd,"\nfromInt\n");
|
||||
int32 ival = 0x7fffffff;
|
||||
for(int i=0; i<3; i++) {
|
||||
convert->fromInt(pvBytePtr, ival);
|
||||
builder.clear(); pvBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"byte %s\n",builder.c_str());
|
||||
convert->fromInt(pvUBytePtr, ival);
|
||||
builder.clear(); pvUBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
|
||||
convert->fromInt(pvShortPtr, ival);
|
||||
builder.clear(); pvShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"short %s\n",builder.c_str());
|
||||
convert->fromInt(pvUShortPtr, ival);
|
||||
builder.clear(); pvUShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
|
||||
convert->fromInt(pvIntPtr, ival);
|
||||
builder.clear(); pvIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"int %s\n",builder.c_str());
|
||||
convert->fromInt(pvUIntPtr, ival);
|
||||
builder.clear(); pvUIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"uint %s\n",builder.c_str());
|
||||
convert->fromInt(pvLongPtr, ival);
|
||||
builder.clear(); pvLongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"long %s\n",builder.c_str());
|
||||
convert->fromInt(pvULongPtr, ival);
|
||||
builder.clear(); pvULongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
|
||||
convert->fromInt(pvFloatPtr, ival);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float %s\n",builder.c_str());
|
||||
convert->fromInt(pvDoublePtr, ival);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double %s\n",builder.c_str());
|
||||
convert->copyScalar(pvUIntPtr, pvFloatPtr);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
|
||||
convert->copyScalar(pvUIntPtr, pvDoublePtr);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
|
||||
ival++;
|
||||
}
|
||||
fprintf(fd,"fromInt PASSED\n");
|
||||
|
||||
if(debug) fprintf(fd,"\nfromLong\n");
|
||||
int64 lval = 0x7fffffffffffffffLL;
|
||||
for(int i=0; i<3; i++) {
|
||||
convert->fromLong(pvBytePtr, lval);
|
||||
builder.clear(); pvBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"byte %s\n",builder.c_str());
|
||||
convert->fromLong(pvUBytePtr, lval);
|
||||
builder.clear(); pvUBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
|
||||
convert->fromLong(pvShortPtr, lval);
|
||||
builder.clear(); pvShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"short %s\n",builder.c_str());
|
||||
convert->fromLong(pvUShortPtr, lval);
|
||||
builder.clear(); pvUShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
|
||||
convert->fromLong(pvIntPtr, lval);
|
||||
builder.clear(); pvIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"int %s\n",builder.c_str());
|
||||
convert->fromLong(pvUIntPtr, lval);
|
||||
builder.clear(); pvUIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"uint %s\n",builder.c_str());
|
||||
convert->fromLong(pvLongPtr, lval);
|
||||
builder.clear(); pvLongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"long %s\n",builder.c_str());
|
||||
convert->fromLong(pvULongPtr, lval);
|
||||
builder.clear(); pvULongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
|
||||
convert->fromLong(pvFloatPtr, lval);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float %s\n",builder.c_str());
|
||||
convert->fromLong(pvDoublePtr, lval);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double %s\n",builder.c_str());
|
||||
convert->copyScalar(pvULongPtr, pvFloatPtr);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
|
||||
convert->copyScalar(pvULongPtr, pvDoublePtr);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
|
||||
lval++;
|
||||
}
|
||||
fprintf(fd,"fromLong PASSED\n");
|
||||
|
||||
if(debug) fprintf(fd,"\nfromUByte\n");
|
||||
uint8 ubval = 127;
|
||||
for(int i=0; i<3; i++) {
|
||||
convert->fromUByte(pvBytePtr, ubval);
|
||||
builder.clear(); pvBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"byte %s\n",builder.c_str());
|
||||
convert->fromUByte(pvUBytePtr, ubval);
|
||||
builder.clear(); pvUBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
|
||||
convert->fromUByte(pvShortPtr, ubval);
|
||||
builder.clear(); pvShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"short %s\n",builder.c_str());
|
||||
convert->fromUByte(pvUShortPtr, ubval);
|
||||
builder.clear(); pvUShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
|
||||
convert->fromUByte(pvIntPtr, ubval);
|
||||
builder.clear(); pvIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"int %s\n",builder.c_str());
|
||||
convert->fromUByte(pvUIntPtr, ubval);
|
||||
builder.clear(); pvUIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"uint %s\n",builder.c_str());
|
||||
convert->fromUByte(pvLongPtr, ubval);
|
||||
builder.clear(); pvLongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"long %s\n",builder.c_str());
|
||||
convert->fromUByte(pvULongPtr, ubval);
|
||||
builder.clear(); pvULongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
|
||||
convert->fromUByte(pvFloatPtr, ubval);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float %s\n",builder.c_str());
|
||||
convert->fromUByte(pvDoublePtr, ubval);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double %s\n",builder.c_str());
|
||||
convert->copyScalar(pvUBytePtr, pvFloatPtr);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
|
||||
convert->copyScalar(pvUBytePtr, pvDoublePtr);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
|
||||
ubval++;
|
||||
}
|
||||
fprintf(fd,"fromUByte PASSED\n");
|
||||
|
||||
if(debug) fprintf(fd,"\nfromUShort\n");
|
||||
uint16 usval = 0x7fff;
|
||||
for(int i=0; i<3; i++) {
|
||||
convert->fromUShort(pvBytePtr, usval);
|
||||
builder.clear(); pvBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"byte %s\n",builder.c_str());
|
||||
convert->fromUShort(pvUBytePtr, usval);
|
||||
builder.clear(); pvUBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
|
||||
convert->fromUShort(pvShortPtr, usval);
|
||||
builder.clear(); pvShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"short %s\n",builder.c_str());
|
||||
convert->fromUShort(pvUShortPtr, usval);
|
||||
builder.clear(); pvUShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
|
||||
convert->fromUShort(pvIntPtr, usval);
|
||||
builder.clear(); pvIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"int %s\n",builder.c_str());
|
||||
convert->fromUShort(pvUIntPtr, usval);
|
||||
builder.clear(); pvUIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"uint %s\n",builder.c_str());
|
||||
convert->fromUShort(pvLongPtr, usval);
|
||||
builder.clear(); pvLongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"long %s\n",builder.c_str());
|
||||
convert->fromUShort(pvULongPtr, usval);
|
||||
builder.clear(); pvULongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
|
||||
convert->fromUShort(pvFloatPtr, usval);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float %s\n",builder.c_str());
|
||||
convert->fromUShort(pvDoublePtr, usval);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double %s\n",builder.c_str());
|
||||
convert->copyScalar(pvUShortPtr, pvFloatPtr);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
|
||||
convert->copyScalar(pvUShortPtr, pvDoublePtr);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
|
||||
usval++;
|
||||
}
|
||||
fprintf(fd,"fromUShort PASSED\n");
|
||||
|
||||
if(debug) fprintf(fd,"\nfromUInt\n");
|
||||
uint32 uival = 0x7fffffff;
|
||||
for(int i=0; i<3; i++) {
|
||||
convert->fromUInt(pvBytePtr, uival);
|
||||
builder.clear(); pvBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"byte %s\n",builder.c_str());
|
||||
convert->fromUInt(pvUBytePtr, uival);
|
||||
builder.clear(); pvUBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
|
||||
convert->fromUInt(pvShortPtr, uival);
|
||||
builder.clear(); pvShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"short %s\n",builder.c_str());
|
||||
convert->fromUInt(pvUShortPtr, uival);
|
||||
builder.clear(); pvUShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
|
||||
convert->fromUInt(pvIntPtr, uival);
|
||||
builder.clear(); pvIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"int %s\n",builder.c_str());
|
||||
convert->fromUInt(pvUIntPtr, uival);
|
||||
builder.clear(); pvUIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"uint %s\n",builder.c_str());
|
||||
convert->fromUInt(pvLongPtr, uival);
|
||||
builder.clear(); pvLongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"long %s\n",builder.c_str());
|
||||
convert->fromUInt(pvULongPtr, uival);
|
||||
builder.clear(); pvULongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
|
||||
convert->fromUInt(pvFloatPtr, uival);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float %s\n",builder.c_str());
|
||||
convert->fromUInt(pvDoublePtr, uival);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double %s\n",builder.c_str());
|
||||
convert->copyScalar(pvUIntPtr, pvFloatPtr);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
|
||||
convert->copyScalar(pvUIntPtr, pvDoublePtr);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
|
||||
uival++;
|
||||
}
|
||||
fprintf(fd,"fromUInt PASSED\n");
|
||||
|
||||
if(debug) fprintf(fd,"\nfromULong\n");
|
||||
uint64 ulval = 0x7fffffffffffffffLL;
|
||||
for(int i=0; i<3; i++) {
|
||||
convert->fromULong(pvBytePtr, ulval);
|
||||
builder.clear(); pvBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"byte %s\n",builder.c_str());
|
||||
convert->fromULong(pvUBytePtr, ulval);
|
||||
builder.clear(); pvUBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
|
||||
convert->fromULong(pvShortPtr, ulval);
|
||||
builder.clear(); pvShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"short %s\n",builder.c_str());
|
||||
convert->fromULong(pvUShortPtr, ulval);
|
||||
builder.clear(); pvUShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
|
||||
convert->fromULong(pvIntPtr, ulval);
|
||||
builder.clear(); pvIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"int %s\n",builder.c_str());
|
||||
convert->fromULong(pvUIntPtr, ulval);
|
||||
builder.clear(); pvUIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"uint %s\n",builder.c_str());
|
||||
convert->fromULong(pvLongPtr, ulval);
|
||||
builder.clear(); pvLongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"long %s\n",builder.c_str());
|
||||
convert->fromULong(pvULongPtr, ulval);
|
||||
builder.clear(); pvULongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
|
||||
convert->fromULong(pvFloatPtr, ulval);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float %s\n",builder.c_str());
|
||||
convert->fromULong(pvDoublePtr, ulval);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double %s\n",builder.c_str());
|
||||
convert->copyScalar(pvULongPtr, pvFloatPtr);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
|
||||
convert->copyScalar(pvULongPtr, pvDoublePtr);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
|
||||
ulval++;
|
||||
}
|
||||
fprintf(fd,"fromULong PASSED\n");
|
||||
}
|
||||
|
||||
static void testConvertScalarArray(FILE *fd) {
|
||||
PVScalarArrayPtr pvBytePtr = pvDataCreate->createPVScalarArray(pvByte);
|
||||
PVScalarArrayPtr pvUBytePtr = pvDataCreate->createPVScalarArray(pvUByte);
|
||||
PVScalarArrayPtr pvShortPtr = pvDataCreate->createPVScalarArray(pvShort);
|
||||
PVScalarArrayPtr pvUShortPtr = pvDataCreate->createPVScalarArray(pvUShort);
|
||||
PVScalarArrayPtr pvIntPtr = pvDataCreate->createPVScalarArray(pvInt);
|
||||
PVScalarArrayPtr pvUIntPtr = pvDataCreate->createPVScalarArray(pvUInt);
|
||||
PVScalarArrayPtr pvLongPtr = pvDataCreate->createPVScalarArray(pvLong);
|
||||
PVScalarArrayPtr pvULongPtr = pvDataCreate->createPVScalarArray(pvULong);
|
||||
PVScalarArrayPtr pvFloatPtr = pvDataCreate->createPVScalarArray(pvFloat);
|
||||
PVScalarArrayPtr pvDoublePtr = pvDataCreate->createPVScalarArray(pvDouble);
|
||||
|
||||
fprintf(fd,"testConvertScalarArray\n");
|
||||
if(debug) fprintf(fd,"\nfromByte\n");
|
||||
size_t length = 4;
|
||||
int8 barray[length];
|
||||
int8 bval = 127;
|
||||
barray[0] = bval;
|
||||
for(size_t i=1; i<length; i++) barray[i] = barray[i-1] + 1;
|
||||
convert->fromByteArray(pvBytePtr,0,length,barray,0);
|
||||
builder.clear(); pvBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"byte %s\n",builder.c_str());
|
||||
convert->fromByteArray(pvUBytePtr,0,length,barray,0);
|
||||
builder.clear(); pvUBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
|
||||
convert->fromByteArray(pvShortPtr,0,length,barray,0);
|
||||
builder.clear(); pvShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"short %s\n",builder.c_str());
|
||||
convert->fromByteArray(pvUShortPtr,0,length,barray,0);
|
||||
builder.clear(); pvUShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
|
||||
convert->fromByteArray(pvIntPtr,0,length,barray,0);
|
||||
builder.clear(); pvIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"int %s\n",builder.c_str());
|
||||
convert->fromByteArray(pvUIntPtr,0,length,barray,0);
|
||||
builder.clear(); pvUIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"uint %s\n",builder.c_str());
|
||||
convert->fromByteArray(pvLongPtr,0,length,barray,0);
|
||||
builder.clear(); pvLongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"long %s\n",builder.c_str());
|
||||
convert->fromByteArray(pvULongPtr,0,length,barray,0);
|
||||
builder.clear(); pvULongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
|
||||
convert->fromByteArray(pvFloatPtr,0,length,barray,0);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float %s\n",builder.c_str());
|
||||
convert->fromByteArray(pvDoublePtr,0,length,barray,0);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double %s\n",builder.c_str());
|
||||
convert->copyScalarArray(pvUBytePtr,0, pvFloatPtr,0,length);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
|
||||
convert->copyScalarArray(pvUBytePtr,0, pvDoublePtr,0,length);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
|
||||
fprintf(fd,"fromByte PASSED\n");
|
||||
|
||||
if(debug) fprintf(fd,"\nfromShort\n");
|
||||
int16 sarray[length];
|
||||
int16 sval = 0x7fff;
|
||||
sarray[0] = sval;
|
||||
for(size_t i=1; i<length; i++) sarray[i] = sarray[i-1] + 1;
|
||||
convert->fromShortArray(pvBytePtr,0,length,sarray,0);
|
||||
builder.clear(); pvBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"byte %s\n",builder.c_str());
|
||||
convert->fromShortArray(pvUBytePtr,0,length,sarray,0);
|
||||
builder.clear(); pvUBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
|
||||
convert->fromShortArray(pvShortPtr,0,length,sarray,0);
|
||||
builder.clear(); pvShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"short %s\n",builder.c_str());
|
||||
convert->fromShortArray(pvUShortPtr,0,length,sarray,0);
|
||||
builder.clear(); pvUShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
|
||||
convert->fromShortArray(pvIntPtr,0,length,sarray,0);
|
||||
builder.clear(); pvIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"int %s\n",builder.c_str());
|
||||
convert->fromShortArray(pvUIntPtr,0,length,sarray,0);
|
||||
builder.clear(); pvUIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"uint %s\n",builder.c_str());
|
||||
convert->fromShortArray(pvLongPtr,0,length,sarray,0);
|
||||
builder.clear(); pvLongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"long %s\n",builder.c_str());
|
||||
convert->fromShortArray(pvULongPtr,0,length,sarray,0);
|
||||
builder.clear(); pvULongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
|
||||
convert->fromShortArray(pvFloatPtr,0,length,sarray,0);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float %s\n",builder.c_str());
|
||||
convert->fromShortArray(pvDoublePtr,0,length,sarray,0);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double %s\n",builder.c_str());
|
||||
convert->copyScalarArray(pvUShortPtr,0, pvFloatPtr,0,length);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
|
||||
convert->copyScalarArray(pvUShortPtr,0, pvDoublePtr,0,length);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
|
||||
fprintf(fd,"fromShort PASSED\n");
|
||||
|
||||
if(debug) fprintf(fd,"\nfromInt\n");
|
||||
int32 iarray[length];
|
||||
int32 ival = 0x7fffffff;
|
||||
iarray[0] = ival;
|
||||
for(size_t i=1; i<length; i++) iarray[i] = iarray[i-1] + 1;
|
||||
convert->fromIntArray(pvBytePtr,0,length,iarray,0);
|
||||
builder.clear(); pvBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"byte %s\n",builder.c_str());
|
||||
convert->fromIntArray(pvUBytePtr,0,length,iarray,0);
|
||||
builder.clear(); pvUBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
|
||||
convert->fromIntArray(pvShortPtr,0,length,iarray,0);
|
||||
builder.clear(); pvShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"short %s\n",builder.c_str());
|
||||
convert->fromIntArray(pvUShortPtr,0,length,iarray,0);
|
||||
builder.clear(); pvUShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
|
||||
convert->fromIntArray(pvIntPtr,0,length,iarray,0);
|
||||
builder.clear(); pvIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"int %s\n",builder.c_str());
|
||||
convert->fromIntArray(pvUIntPtr,0,length,iarray,0);
|
||||
builder.clear(); pvUIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"uint %s\n",builder.c_str());
|
||||
convert->fromIntArray(pvLongPtr,0,length,iarray,0);
|
||||
builder.clear(); pvLongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"long %s\n",builder.c_str());
|
||||
convert->fromIntArray(pvULongPtr,0,length,iarray,0);
|
||||
builder.clear(); pvULongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
|
||||
convert->fromIntArray(pvFloatPtr,0,length,iarray,0);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float %s\n",builder.c_str());
|
||||
convert->fromIntArray(pvDoublePtr,0,length,iarray,0);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double %s\n",builder.c_str());
|
||||
convert->copyScalarArray(pvUIntPtr,0, pvFloatPtr,0,length);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
|
||||
convert->copyScalarArray(pvUIntPtr,0, pvDoublePtr,0,length);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
|
||||
fprintf(fd,"fromInt PASSED\n");
|
||||
|
||||
if(debug) fprintf(fd,"\nfromLong\n");
|
||||
int64 larray[length];
|
||||
int64 lval = 0x7fffffffffffffffLL;
|
||||
larray[0] = lval;
|
||||
for(size_t i=1; i<length; i++) larray[i] = larray[i-1] + 1;
|
||||
convert->fromLongArray(pvBytePtr,0,length,larray,0);
|
||||
builder.clear(); pvBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"byte %s\n",builder.c_str());
|
||||
convert->fromLongArray(pvUBytePtr,0,length,larray,0);
|
||||
builder.clear(); pvUBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
|
||||
convert->fromLongArray(pvShortPtr,0,length,larray,0);
|
||||
builder.clear(); pvShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"short %s\n",builder.c_str());
|
||||
convert->fromLongArray(pvUShortPtr,0,length,larray,0);
|
||||
builder.clear(); pvUShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
|
||||
convert->fromLongArray(pvIntPtr,0,length,larray,0);
|
||||
builder.clear(); pvIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"int %s\n",builder.c_str());
|
||||
convert->fromLongArray(pvUIntPtr,0,length,larray,0);
|
||||
builder.clear(); pvUIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"uint %s\n",builder.c_str());
|
||||
convert->fromLongArray(pvLongPtr,0,length,larray,0);
|
||||
builder.clear(); pvLongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"long %s\n",builder.c_str());
|
||||
convert->fromLongArray(pvULongPtr,0,length,larray,0);
|
||||
builder.clear(); pvULongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
|
||||
convert->fromLongArray(pvFloatPtr,0,length,larray,0);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float %s\n",builder.c_str());
|
||||
convert->fromLongArray(pvDoublePtr,0,length,larray,0);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double %s\n",builder.c_str());
|
||||
convert->copyScalarArray(pvULongPtr,0, pvFloatPtr,0,length);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
|
||||
convert->copyScalarArray(pvULongPtr,0, pvDoublePtr,0,length);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
|
||||
fprintf(fd,"fromLong PASSED\n");
|
||||
|
||||
if(debug) fprintf(fd,"\nfromUByte\n");
|
||||
uint8 ubarray[length];
|
||||
uint8 ubval = 127;
|
||||
ubarray[0] = ubval;
|
||||
for(size_t i=1; i<length; i++) ubarray[i] = ubarray[i-1] + 1;
|
||||
convert->fromUByteArray(pvBytePtr,0,length,ubarray,0);
|
||||
builder.clear(); pvBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"byte %s\n",builder.c_str());
|
||||
convert->fromUByteArray(pvUBytePtr,0,length,ubarray,0);
|
||||
builder.clear(); pvUBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
|
||||
convert->fromUByteArray(pvShortPtr,0,length,ubarray,0);
|
||||
builder.clear(); pvShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"short %s\n",builder.c_str());
|
||||
convert->fromUByteArray(pvUShortPtr,0,length,ubarray,0);
|
||||
builder.clear(); pvUShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
|
||||
convert->fromUByteArray(pvIntPtr,0,length,ubarray,0);
|
||||
builder.clear(); pvIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"int %s\n",builder.c_str());
|
||||
convert->fromUByteArray(pvUIntPtr,0,length,ubarray,0);
|
||||
builder.clear(); pvUIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"uint %s\n",builder.c_str());
|
||||
convert->fromUByteArray(pvLongPtr,0,length,ubarray,0);
|
||||
builder.clear(); pvLongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"long %s\n",builder.c_str());
|
||||
convert->fromUByteArray(pvULongPtr,0,length,ubarray,0);
|
||||
builder.clear(); pvULongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
|
||||
convert->fromUByteArray(pvFloatPtr,0,length,ubarray,0);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float %s\n",builder.c_str());
|
||||
convert->fromUByteArray(pvDoublePtr,0,length,ubarray,0);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double %s\n",builder.c_str());
|
||||
convert->copyScalarArray(pvUBytePtr,0, pvFloatPtr,0,length);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
|
||||
convert->copyScalarArray(pvUBytePtr,0, pvDoublePtr,0,length);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
|
||||
fprintf(fd,"fromUByte PASSED\n");
|
||||
|
||||
if(debug) fprintf(fd,"\nfromUShort\n");
|
||||
uint16 usarray[length];
|
||||
uint16 usval = 0x7fff;
|
||||
usarray[0] = usval;
|
||||
for(size_t i=1; i<length; i++) usarray[i] = usarray[i-1] + 1;
|
||||
convert->fromUShortArray(pvBytePtr,0,length,usarray,0);
|
||||
builder.clear(); pvBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"byte %s\n",builder.c_str());
|
||||
convert->fromUShortArray(pvUBytePtr,0,length,usarray,0);
|
||||
builder.clear(); pvUBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
|
||||
convert->fromUShortArray(pvShortPtr,0,length,usarray,0);
|
||||
builder.clear(); pvShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"short %s\n",builder.c_str());
|
||||
convert->fromUShortArray(pvUShortPtr,0,length,usarray,0);
|
||||
builder.clear(); pvUShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
|
||||
convert->fromUShortArray(pvIntPtr,0,length,usarray,0);
|
||||
builder.clear(); pvIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"int %s\n",builder.c_str());
|
||||
convert->fromUShortArray(pvUIntPtr,0,length,usarray,0);
|
||||
builder.clear(); pvUIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"uint %s\n",builder.c_str());
|
||||
convert->fromUShortArray(pvLongPtr,0,length,usarray,0);
|
||||
builder.clear(); pvLongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"long %s\n",builder.c_str());
|
||||
convert->fromUShortArray(pvULongPtr,0,length,usarray,0);
|
||||
builder.clear(); pvULongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
|
||||
convert->fromUShortArray(pvFloatPtr,0,length,usarray,0);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float %s\n",builder.c_str());
|
||||
convert->fromUShortArray(pvDoublePtr,0,length,usarray,0);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double %s\n",builder.c_str());
|
||||
convert->copyScalarArray(pvUShortPtr,0, pvFloatPtr,0,length);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
|
||||
convert->copyScalarArray(pvUShortPtr,0, pvDoublePtr,0,length);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
|
||||
fprintf(fd,"fromUShort PASSED\n");
|
||||
|
||||
if(debug) fprintf(fd,"\nfromUInt\n");
|
||||
uint32 uiarray[length];
|
||||
uint32 uival = 0x7fffffff;
|
||||
uiarray[0] = uival;
|
||||
for(size_t i=1; i<length; i++) uiarray[i] = uiarray[i-1] + 1;
|
||||
convert->fromUIntArray(pvBytePtr,0,length,uiarray,0);
|
||||
builder.clear(); pvBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"byte %s\n",builder.c_str());
|
||||
convert->fromUIntArray(pvUBytePtr,0,length,uiarray,0);
|
||||
builder.clear(); pvUBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
|
||||
convert->fromUIntArray(pvShortPtr,0,length,uiarray,0);
|
||||
builder.clear(); pvShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"short %s\n",builder.c_str());
|
||||
convert->fromUIntArray(pvUShortPtr,0,length,uiarray,0);
|
||||
builder.clear(); pvUShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
|
||||
convert->fromUIntArray(pvIntPtr,0,length,uiarray,0);
|
||||
builder.clear(); pvIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"int %s\n",builder.c_str());
|
||||
convert->fromUIntArray(pvUIntPtr,0,length,uiarray,0);
|
||||
builder.clear(); pvUIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"uint %s\n",builder.c_str());
|
||||
convert->fromUIntArray(pvLongPtr,0,length,uiarray,0);
|
||||
builder.clear(); pvLongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"long %s\n",builder.c_str());
|
||||
convert->fromUIntArray(pvULongPtr,0,length,uiarray,0);
|
||||
builder.clear(); pvULongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
|
||||
convert->fromUIntArray(pvFloatPtr,0,length,uiarray,0);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float %s\n",builder.c_str());
|
||||
convert->fromUIntArray(pvDoublePtr,0,length,uiarray,0);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double %s\n",builder.c_str());
|
||||
convert->copyScalarArray(pvUIntPtr,0, pvFloatPtr,0,length);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
|
||||
convert->copyScalarArray(pvUIntPtr,0, pvDoublePtr,0,length);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
|
||||
fprintf(fd,"fromUInt PASSED\n");
|
||||
|
||||
if(debug) fprintf(fd,"\nfromULong\n");
|
||||
uint64 ularray[length];
|
||||
uint64 ulval = 0x7fffffffffffffffLL;
|
||||
ularray[0] = ulval;
|
||||
for(size_t i=1; i<length; i++) ularray[i] = ularray[i-1] + 1;
|
||||
convert->fromULongArray(pvBytePtr,0,length,ularray,0);
|
||||
builder.clear(); pvBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"byte %s\n",builder.c_str());
|
||||
convert->fromULongArray(pvUBytePtr,0,length,ularray,0);
|
||||
builder.clear(); pvUBytePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
|
||||
convert->fromULongArray(pvShortPtr,0,length,ularray,0);
|
||||
builder.clear(); pvShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"short %s\n",builder.c_str());
|
||||
convert->fromULongArray(pvUShortPtr,0,length,ularray,0);
|
||||
builder.clear(); pvUShortPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
|
||||
convert->fromULongArray(pvIntPtr,0,length,ularray,0);
|
||||
builder.clear(); pvIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"int %s\n",builder.c_str());
|
||||
convert->fromULongArray(pvUIntPtr,0,length,ularray,0);
|
||||
builder.clear(); pvUIntPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"uint %s\n",builder.c_str());
|
||||
convert->fromULongArray(pvLongPtr,0,length,ularray,0);
|
||||
builder.clear(); pvLongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"long %s\n",builder.c_str());
|
||||
convert->fromULongArray(pvULongPtr,0,length,ularray,0);
|
||||
builder.clear(); pvULongPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
|
||||
convert->fromULongArray(pvFloatPtr,0,length,ularray,0);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float %s\n",builder.c_str());
|
||||
convert->fromULongArray(pvDoublePtr,0,length,ularray,0);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double %s\n",builder.c_str());
|
||||
convert->copyScalarArray(pvULongPtr,0, pvFloatPtr,0,length);
|
||||
builder.clear(); pvFloatPtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
|
||||
convert->copyScalarArray(pvULongPtr,0, pvDoublePtr,0,length);
|
||||
builder.clear(); pvDoublePtr->toString(&builder);
|
||||
if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
|
||||
fprintf(fd,"fromLong PASSED\n");
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
static void testFromString()
|
||||
{
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
fieldCreate = getFieldCreate();
|
||||
pvDataCreate = getPVDataCreate();
|
||||
standardField = getStandardField();
|
||||
standardPVField = getStandardPVField();
|
||||
convert = getConvert();
|
||||
testConvertScalar(fd);
|
||||
testConvertScalarArray(fd);
|
||||
fprintf(fd,"THIS NEEDS MANY MORE TESTS AND ASSERTS\n");
|
||||
return(0);
|
||||
StringArray inp(2);
|
||||
|
||||
inp[0] = "0";
|
||||
inp[1] = "1";
|
||||
|
||||
PVScalarArrayPtr A(getPVDataCreate()->createPVScalarArray(pvInt));
|
||||
PVScalarArrayPtr B(getPVDataCreate()->createPVScalarArray(pvString));
|
||||
|
||||
testOk1(2==getConvert()->fromStringArray(A, 0, inp.size(), inp, 0));
|
||||
testOk1(2==getConvert()->fromStringArray(B, 0, inp.size(), inp, 0));
|
||||
|
||||
PVIntArrayPtr Ax(std::tr1::static_pointer_cast<PVIntArray>(A));
|
||||
PVStringArrayPtr Bx(std::tr1::static_pointer_cast<PVStringArray>(B));
|
||||
|
||||
PVIntArray::const_svector Adata(Ax->view());
|
||||
PVStringArray::const_svector Bdata(Bx->view());
|
||||
|
||||
testOk1(inp.size()==Adata.size());
|
||||
if(inp.size()==Adata.size())
|
||||
testOk1(Adata[0]==0 && Adata[1]==1);
|
||||
else
|
||||
testFail("Can't compare");
|
||||
|
||||
testOk1(inp.size()==Bdata.size());
|
||||
if(inp.size()==Bdata.size())
|
||||
testOk1(Bdata[0]=="0" && Bdata[1]=="1");
|
||||
else
|
||||
testFail("Can't compare");
|
||||
}
|
||||
|
||||
MAIN(testConvert)
|
||||
{
|
||||
testPlan(0);
|
||||
testFromString();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
+158
-98
@@ -12,8 +12,8 @@
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsExit.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/requester.h>
|
||||
#include <pv/executor.h>
|
||||
@@ -23,130 +23,190 @@
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
static bool debug = false;
|
||||
|
||||
static FieldCreatePtr fieldCreate;
|
||||
static PVDataCreatePtr pvDataCreate;
|
||||
static StandardFieldPtr standardField;
|
||||
static String builder("");
|
||||
|
||||
static void testScalarCommon(FILE * fd,ScalarType stype,
|
||||
static void testScalarCommon(ScalarType stype,
|
||||
bool isInteger,bool isNumeric,bool isPrimitive)
|
||||
{
|
||||
String builder;
|
||||
ScalarConstPtr pscalar = fieldCreate->createScalar(stype);
|
||||
Type type = pscalar->getType();
|
||||
assert(type==scalar);
|
||||
testOk1(type==scalar);
|
||||
builder.clear();
|
||||
TypeFunc::toString(&builder,type);
|
||||
assert(builder.compare("scalar")==0);
|
||||
testOk1(builder.compare("scalar")==0);
|
||||
ScalarType scalarType = pscalar->getScalarType();
|
||||
assert(scalarType==stype);
|
||||
assert(ScalarTypeFunc::isInteger(scalarType)==isInteger);
|
||||
assert(ScalarTypeFunc::isNumeric(scalarType)==isNumeric);
|
||||
assert(ScalarTypeFunc::isPrimitive(scalarType)==isPrimitive);
|
||||
builder.clear();
|
||||
pscalar->toString(&builder);
|
||||
if(debug) fprintf(fd,"%s\n",builder.c_str());
|
||||
testOk1(scalarType==stype);
|
||||
testOk1(ScalarTypeFunc::isInteger(scalarType)==isInteger);
|
||||
testOk1(ScalarTypeFunc::isNumeric(scalarType)==isNumeric);
|
||||
testOk1(ScalarTypeFunc::isPrimitive(scalarType)==isPrimitive);
|
||||
}
|
||||
|
||||
static void testScalar(FILE * fd) {
|
||||
if(debug) fprintf(fd,"\ntestScalar\n");
|
||||
testScalarCommon(fd,pvBoolean,false,false,true);
|
||||
testScalarCommon(fd,pvByte,true,true,true);
|
||||
testScalarCommon(fd,pvShort,true,true,true);
|
||||
testScalarCommon(fd,pvInt,true,true,true);
|
||||
testScalarCommon(fd,pvLong,true,true,true);
|
||||
testScalarCommon(fd,pvFloat,false,true,true);
|
||||
testScalarCommon(fd,pvDouble,false,true,true);
|
||||
testScalarCommon(fd,pvString,false,false,false);
|
||||
fprintf(fd,"testScalar PASSED\n");
|
||||
static void testScalar() {
|
||||
testDiag("testScalar");
|
||||
testScalarCommon(pvBoolean,false,false,true);
|
||||
testScalarCommon(pvByte,true,true,true);
|
||||
testScalarCommon(pvShort,true,true,true);
|
||||
testScalarCommon(pvInt,true,true,true);
|
||||
testScalarCommon(pvLong,true,true,true);
|
||||
testScalarCommon(pvFloat,false,true,true);
|
||||
testScalarCommon(pvDouble,false,true,true);
|
||||
testScalarCommon(pvString,false,false,false);
|
||||
}
|
||||
|
||||
static void testScalarArrayCommon(FILE * fd,ScalarType stype,
|
||||
static void testScalarArrayCommon(ScalarType stype,
|
||||
bool isInteger,bool isNumeric,bool isPrimitive)
|
||||
{
|
||||
String builder;
|
||||
ScalarArrayConstPtr pscalar = fieldCreate->createScalarArray(stype);
|
||||
Type type = pscalar->getType();
|
||||
assert(type==scalarArray);
|
||||
testOk1(type==scalarArray);
|
||||
builder.clear();
|
||||
TypeFunc::toString(&builder,type);
|
||||
assert(builder.compare("scalarArray")==0);
|
||||
testOk1(builder.compare("scalarArray")==0);
|
||||
ScalarType scalarType = pscalar->getElementType();
|
||||
assert(scalarType==stype);
|
||||
assert(ScalarTypeFunc::isInteger(scalarType)==isInteger);
|
||||
assert(ScalarTypeFunc::isNumeric(scalarType)==isNumeric);
|
||||
assert(ScalarTypeFunc::isPrimitive(scalarType)==isPrimitive);
|
||||
builder.clear();
|
||||
pscalar->toString(&builder);
|
||||
if(debug) fprintf(fd,"%s\n",builder.c_str());
|
||||
testOk1(scalarType==stype);
|
||||
testOk1(ScalarTypeFunc::isInteger(scalarType)==isInteger);
|
||||
testOk1(ScalarTypeFunc::isNumeric(scalarType)==isNumeric);
|
||||
testOk1(ScalarTypeFunc::isPrimitive(scalarType)==isPrimitive);
|
||||
}
|
||||
|
||||
static void testScalarArray(FILE * fd) {
|
||||
if(debug) fprintf(fd,"\ntestScalarArray\n");
|
||||
testScalarArrayCommon(fd,pvBoolean,false,false,true);
|
||||
testScalarArrayCommon(fd,pvByte,true,true,true);
|
||||
testScalarArrayCommon(fd,pvShort,true,true,true);
|
||||
testScalarArrayCommon(fd,pvInt,true,true,true);
|
||||
testScalarArrayCommon(fd,pvLong,true,true,true);
|
||||
testScalarArrayCommon(fd,pvFloat,false,true,true);
|
||||
testScalarArrayCommon(fd,pvDouble,false,true,true);
|
||||
testScalarArrayCommon(fd,pvString,false,false,false);
|
||||
fprintf(fd,"testScalarArray PASSED\n");
|
||||
static void testScalarArray() {
|
||||
testDiag("testScalarArray");
|
||||
testScalarArrayCommon(pvBoolean,false,false,true);
|
||||
testScalarArrayCommon(pvByte,true,true,true);
|
||||
testScalarArrayCommon(pvShort,true,true,true);
|
||||
testScalarArrayCommon(pvInt,true,true,true);
|
||||
testScalarArrayCommon(pvLong,true,true,true);
|
||||
testScalarArrayCommon(pvFloat,false,true,true);
|
||||
testScalarArrayCommon(pvDouble,false,true,true);
|
||||
testScalarArrayCommon(pvString,false,false,false);
|
||||
}
|
||||
|
||||
static void testSimpleStructure(FILE * fd) {
|
||||
if(debug) fprintf(fd,"\ntestSimpleStructure\n");
|
||||
String properties("alarm,timeStamp,display,control,valueAlarm");
|
||||
StructureConstPtr ptop = standardField->scalar(pvDouble,properties);
|
||||
builder.clear();
|
||||
ptop->toString(&builder);
|
||||
if(debug) fprintf(fd,"%s\n",builder.c_str());
|
||||
fprintf(fd,"testSimpleStructure PASSED\n");
|
||||
}
|
||||
|
||||
static StructureConstPtr createPowerSupply() {
|
||||
size_t nfields = 3;
|
||||
String properties("alarm");
|
||||
StringArray names;
|
||||
names.reserve(nfields);
|
||||
FieldConstPtrArray powerSupply;
|
||||
powerSupply.reserve(nfields);
|
||||
names.push_back("voltage");
|
||||
powerSupply.push_back(standardField->scalar(pvDouble,properties));
|
||||
names.push_back("power");
|
||||
powerSupply.push_back(standardField->scalar(pvDouble,properties));
|
||||
names.push_back("current");
|
||||
powerSupply.push_back(standardField->scalar(pvDouble,properties));
|
||||
return fieldCreate->createStructure(names,powerSupply);
|
||||
}
|
||||
|
||||
static void testStructureArray(FILE * fd) {
|
||||
if(debug) fprintf(fd,"\ntestStructureArray\n");
|
||||
String properties("alarm,timeStamp");
|
||||
StructureConstPtr powerSupply = createPowerSupply();
|
||||
StructureConstPtr top = standardField->structureArray(
|
||||
powerSupply,properties);
|
||||
builder.clear();
|
||||
top->toString(&builder);
|
||||
if(debug) fprintf(fd,"%s\n",builder.c_str());
|
||||
fprintf(fd,"testStructureArray PASSED\n");
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
static void testStructure()
|
||||
{
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
testDiag("testStructure");
|
||||
StringArray names1(2);
|
||||
names1[0] = "innerA";
|
||||
names1[1] = "innerB";
|
||||
FieldConstPtrArray fields1(2);
|
||||
fields1[0] = fieldCreate->createScalar(pvDouble);
|
||||
fields1[1] = fieldCreate->createScalarArray(pvString);
|
||||
|
||||
StructureConstPtr struct1 = fieldCreate->createStructure(names1, fields1);
|
||||
|
||||
testOk1(struct1->getNumberFields()==2);
|
||||
testOk1(struct1->getField("innerA")==fields1[0]);
|
||||
testOk1(struct1->getField("innerB")==fields1[1]);
|
||||
testOk1(struct1->getFieldIndex("innerA")==0);
|
||||
testOk1(struct1->getFieldIndex("innerB")==1);
|
||||
testOk1(struct1->getField(0)==fields1[0]);
|
||||
testOk1(struct1->getField(1)==fields1[1]);
|
||||
testOk1(struct1->getFieldName(0)==names1[0]);
|
||||
testOk1(struct1->getFieldName(1)==names1[1]);
|
||||
|
||||
testOk1(struct1->getID() == Structure::DEFAULT_ID);
|
||||
|
||||
testOk1(fields1 == struct1->getFields()); // vector equality
|
||||
|
||||
StringArray names2(2);
|
||||
names2[0] = "outerA";
|
||||
names2[1] = "outerB";
|
||||
FieldConstPtrArray fields2(2);
|
||||
fields2[0] = fieldCreate->createScalar(pvInt);
|
||||
fields2[1] = std::tr1::static_pointer_cast<const Field>(struct1);
|
||||
|
||||
StructureConstPtr struct2 = fieldCreate->createStructure(names2, fields2);
|
||||
|
||||
testOk1(struct2->getNumberFields()==2); // not recursive
|
||||
testOk1(struct2->getField(1)==fields2[1]);
|
||||
|
||||
StructureArrayConstPtr struct1arr = fieldCreate->createStructureArray(struct1);
|
||||
|
||||
testOk1(struct1arr->getStructure()==struct1);
|
||||
testOk1(struct1arr->getID()=="structure[]");
|
||||
}
|
||||
|
||||
#define testExcept(EXCEPT, CMD) try{ CMD; testFail( "No exception from: " #CMD); } \
|
||||
catch(EXCEPT& e) {testPass("Got expected exception from: " #CMD);} \
|
||||
catch(std::exception& e) {testFail("Got wrong exception %s(%s) from: " #CMD, typeid(e).name(),e.what());} \
|
||||
catch(...) {testFail("Got unknown execption from: " #CMD);}
|
||||
|
||||
static void testError()
|
||||
{
|
||||
testDiag("testError");
|
||||
ScalarType invalidtype = (ScalarType)9999;
|
||||
|
||||
testExcept(std::invalid_argument, ScalarTypeFunc::getScalarType("invalidtype"));
|
||||
|
||||
testExcept(std::invalid_argument, ScalarTypeFunc::elementSize(invalidtype));
|
||||
|
||||
testExcept(std::invalid_argument, ScalarTypeFunc::name(invalidtype));
|
||||
|
||||
testOk1(!ScalarTypeFunc::isInteger(invalidtype));
|
||||
testOk1(!ScalarTypeFunc::isUInteger(invalidtype));
|
||||
testOk1(!ScalarTypeFunc::isNumeric(invalidtype));
|
||||
testOk1(!ScalarTypeFunc::isPrimitive(invalidtype));
|
||||
|
||||
testExcept(std::invalid_argument, fieldCreate->createScalar(invalidtype));
|
||||
testExcept(std::invalid_argument, fieldCreate->createScalarArray(invalidtype));
|
||||
|
||||
StringArray names;
|
||||
FieldConstPtrArray fields(1);
|
||||
|
||||
// fails because names.size()!=fields.size()
|
||||
testExcept(std::invalid_argument, fieldCreate->createStructure(names,fields));
|
||||
|
||||
names.resize(1);;
|
||||
|
||||
// fails because names[0].size()==0
|
||||
testExcept(std::invalid_argument, fieldCreate->createStructure(names,fields));
|
||||
|
||||
names[0] = "hello";
|
||||
|
||||
// fails because fields[0].get()==NULL
|
||||
testExcept(std::invalid_argument, fieldCreate->createStructure(names,fields));
|
||||
|
||||
fields[0] = std::tr1::static_pointer_cast<const Field>(fieldCreate->createScalar(pvDouble));
|
||||
|
||||
testOk1(fieldCreate->createStructure(names,fields).get()!=NULL);
|
||||
}
|
||||
|
||||
static void testMapping()
|
||||
{
|
||||
#define OP(TYPE, ENUM) \
|
||||
testOk1(typeid(ScalarTypeTraits<ENUM>::type)==typeid(TYPE)); \
|
||||
testOk1(ENUM==(ScalarType)ScalarTypeID<TYPE>::value); \
|
||||
testOk1(ENUM==(ScalarType)ScalarTypeID<const TYPE>::value);
|
||||
OP(boolean, pvBoolean)
|
||||
OP(int8, pvByte)
|
||||
OP(int16, pvShort)
|
||||
OP(int32, pvInt)
|
||||
OP(int64, pvLong)
|
||||
OP(uint8, pvUByte)
|
||||
OP(uint16, pvUShort)
|
||||
OP(uint32, pvUInt)
|
||||
OP(uint64, pvULong)
|
||||
OP(float, pvFloat)
|
||||
OP(double, pvDouble)
|
||||
OP(String, pvString)
|
||||
#undef OP
|
||||
|
||||
testOk1((ScalarType)ScalarTypeID<PVField>::value==(ScalarType)-1);
|
||||
}
|
||||
|
||||
MAIN(testIntrospect)
|
||||
{
|
||||
testPlan(161);
|
||||
fieldCreate = getFieldCreate();
|
||||
pvDataCreate = getPVDataCreate();
|
||||
standardField = getStandardField();
|
||||
testScalar(fd);
|
||||
testScalarArray(fd);
|
||||
testSimpleStructure(fd);
|
||||
testStructureArray(fd);
|
||||
return(0);
|
||||
testScalar();
|
||||
testScalarArray();
|
||||
testStructure();
|
||||
testError();
|
||||
testMapping();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
||||
@@ -66,9 +66,10 @@ int main(int, char **)
|
||||
pvStructure = standardPVField->scalarArray(pvDouble,"alarm,timeStamp");
|
||||
std::cout << *pvStructure << std::endl;
|
||||
|
||||
double values[] = { 1.1, 2.2, 3.3 };
|
||||
PVDoubleArray::svector values(3);
|
||||
values[0] = 1.1; values[1] = 2.2; values[2] = 3.3;
|
||||
PVDoubleArrayPtr darray = std::tr1::dynamic_pointer_cast<PVDoubleArray>(pvStructure->getScalarArrayField("value", pvDouble));
|
||||
darray->put(0, 3, values, 0);
|
||||
darray->replace(freeze(values));
|
||||
std::cout << *darray << std::endl;
|
||||
std::cout << format::array_at(1) << *darray << std::endl;
|
||||
|
||||
@@ -76,14 +77,13 @@ int main(int, char **)
|
||||
StructureConstPtr structure = standardField->scalar(pvDouble, "alarm,timeStamp");
|
||||
pvStructure = standardPVField->structureArray(structure,"alarm,timeStamp");
|
||||
size_t num = 2;
|
||||
PVStructurePtrArray pvStructures;
|
||||
pvStructures.reserve(num);
|
||||
PVStructureArray::svector pvStructures(num);
|
||||
for(size_t i=0; i<num; i++) {
|
||||
pvStructures.push_back(
|
||||
pvDataCreate->createPVStructure(structure));
|
||||
pvStructures[i]=
|
||||
pvDataCreate->createPVStructure(structure);
|
||||
}
|
||||
PVStructureArrayPtr pvStructureArray = pvStructure->getStructureArrayField("value");
|
||||
pvStructureArray->put(0, num, pvStructures, 0);
|
||||
pvStructureArray->replace(freeze(pvStructures));
|
||||
std::cout << *pvStructure << std::endl;
|
||||
|
||||
return 0;
|
||||
|
||||
+146
-331
@@ -14,6 +14,8 @@
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsExit.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/requester.h>
|
||||
#include <pv/pvIntrospect.h>
|
||||
@@ -25,352 +27,165 @@
|
||||
using namespace epics::pvData;
|
||||
using std::tr1::static_pointer_cast;
|
||||
|
||||
static bool debug = false;
|
||||
namespace {
|
||||
|
||||
static FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
static PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
static StandardFieldPtr standardField = getStandardField();
|
||||
static StandardPVFieldPtr standardPVField = getStandardPVField();
|
||||
static ConvertPtr convert = getConvert();
|
||||
static String builder;
|
||||
static String alarmTimeStamp("alarm,timeStamp");
|
||||
static String alarmTimeStampValueAlarm("alarm,timeStamp,valueAlarm");
|
||||
static String allProperties("alarm,timeStamp,display,control,valueAlarm");
|
||||
static FILE * fd = NULL;
|
||||
static size_t length = 4;
|
||||
|
||||
static void byteArray()
|
||||
static void testFactory()
|
||||
{
|
||||
if(debug) fprintf(fd,"\nbyteArray\n");
|
||||
PVScalarArrayPtr pvScalarArray = pvDataCreate->createPVScalarArray(pvByte);;
|
||||
PVByteArrayPtr pvByteArray = static_pointer_cast<PVByteArray>(pvScalarArray);
|
||||
ByteArray value;
|
||||
value.reserve(length);
|
||||
int8 xxx = 0x7f;
|
||||
for(size_t i = 0; i<length; i++) value.push_back(xxx++);
|
||||
pvByteArray->put(0,length,value,0);
|
||||
builder.clear();
|
||||
pvByteArray->toString(&builder);
|
||||
if(debug) fprintf(fd,"put\n%s\n",builder.c_str());
|
||||
convert->fromByteArray(pvScalarArray,0,length,value,0);
|
||||
builder.clear();
|
||||
pvByteArray->toString(&builder);
|
||||
if(debug) fprintf(fd,"convert\n%s\n",builder.c_str());
|
||||
ByteArrayData data;
|
||||
pvByteArray->get(0,length,data);
|
||||
ByteArray_iterator iter = data.data.begin();
|
||||
if(debug) fprintf(fd,"iter [");
|
||||
for(iter=data.data.begin();iter!=data.data.end();++iter) {
|
||||
if(debug) fprintf(fd,"%d ",*iter);
|
||||
testDiag("Check array creation");
|
||||
|
||||
for(ScalarType e=pvBoolean; e<=pvString; e=(ScalarType)(1+(int)e))
|
||||
{
|
||||
testDiag("Check type %s", ScalarTypeFunc::name(e));
|
||||
PVScalarArrayPtr arr = getPVDataCreate()->createPVScalarArray(e);
|
||||
testOk1(arr.get()!=NULL);
|
||||
if(!arr.get())
|
||||
continue;
|
||||
testOk1(arr->getScalarArray()->getElementType()==e);
|
||||
testOk1(arr->getLength()==0);
|
||||
arr->setLength(10);
|
||||
testOk1(arr->getLength()==10);
|
||||
testOk1(arr->getCapacity()>=10);
|
||||
arr->setLength(0);
|
||||
testOk1(arr->getLength()==0);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
if(debug) fprintf(fd,"raw [");
|
||||
int8 * pdata = get(data.data);
|
||||
for(size_t i=0; i<length; i++) {
|
||||
int val = pdata[i];
|
||||
if(debug) fprintf(fd,"%d ",val);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
if(debug) fprintf(fd,"direct[");
|
||||
for(size_t i=0; i<length; i++) {
|
||||
int val = data.data[i];
|
||||
if(debug) fprintf(fd,"%d ",val);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
fprintf(fd,"byteArray PASSED\n");
|
||||
}
|
||||
|
||||
static void ubyteArray()
|
||||
template<typename PVT>
|
||||
bool hasUniqueVector(const typename PVT::shared_pointer& pv)
|
||||
{
|
||||
if(debug) fprintf(fd,"\nubyteArray\n");
|
||||
PVScalarArrayPtr pvScalarArray = pvDataCreate->createPVScalarArray(pvUByte);;
|
||||
PVUByteArrayPtr pvUByteArray = static_pointer_cast<PVUByteArray>(pvScalarArray);
|
||||
UByteArray value;
|
||||
value.reserve(length);
|
||||
uint8 xxx = 0x7f;
|
||||
for(size_t i = 0; i<length; i++) value.push_back(xxx++);
|
||||
pvUByteArray->put(0,length,value,0);
|
||||
builder.clear();
|
||||
pvUByteArray->toString(&builder);
|
||||
if(debug) fprintf(fd,"put\n%s\n",builder.c_str());
|
||||
convert->fromUByteArray(pvScalarArray,0,length,value,0);
|
||||
builder.clear();
|
||||
pvUByteArray->toString(&builder);
|
||||
if(debug) fprintf(fd,"convert\n%s\n",builder.c_str());
|
||||
UByteArrayData data;
|
||||
pvUByteArray->get(0,length,data);
|
||||
UByteArray_iterator iter = data.data.begin();
|
||||
if(debug) fprintf(fd,"iter [");
|
||||
for(iter=data.data.begin();iter!=data.data.end();++iter) {
|
||||
if(debug) fprintf(fd,"%u ",*iter);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
if(debug) fprintf(fd,"raw [");
|
||||
uint8 * pdata = get(data.data);
|
||||
for(size_t i=0; i<length; i++) {
|
||||
unsigned int val = pdata[i];
|
||||
if(debug) fprintf(fd,"%d ",val);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
if(debug) fprintf(fd,"direct[");
|
||||
for(size_t i=0; i<length; i++) {
|
||||
unsigned int val = data.data[i];
|
||||
if(debug) fprintf(fd,"%d ",val);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
fprintf(fd,"ubyteArray PASSED\n");
|
||||
typename PVT::const_svector data;
|
||||
pv->swap(data);
|
||||
bool ret = data.unique();
|
||||
pv->swap(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void longArray()
|
||||
template<typename PVT>
|
||||
struct basicTestData {
|
||||
static inline void fill(typename PVT::svector& data) {
|
||||
data.resize(100);
|
||||
for(size_t i=0; i<data.size(); i++)
|
||||
{
|
||||
data[i] = 10*i;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
struct basicTestData<PVStringArray> {
|
||||
static inline void fill(PVStringArray::svector& data) {
|
||||
PVIntArray::svector idata;
|
||||
basicTestData<PVIntArray>::fill(idata);
|
||||
data.resize(idata.size());
|
||||
castUnsafeV(data.size(), pvString, data.data(), pvInt, idata.data());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename PVT>
|
||||
static void testBasic()
|
||||
{
|
||||
if(debug) fprintf(fd,"\nlongArray\n");
|
||||
PVScalarArrayPtr pvScalarArray = pvDataCreate->createPVScalarArray(pvLong);;
|
||||
PVLongArrayPtr pvLongArray = static_pointer_cast<PVLongArray>(pvScalarArray);
|
||||
LongArray value;
|
||||
value.reserve(length);
|
||||
int64 xxx = 0x7fffffffffffffffLL;
|
||||
for(size_t i = 0; i<length; i++) value.push_back(xxx++);
|
||||
pvLongArray->put(0,length,value,0);
|
||||
builder.clear();
|
||||
pvLongArray->toString(&builder);
|
||||
if(debug) fprintf(fd,"put\n%s\n",builder.c_str());
|
||||
convert->fromLongArray(pvScalarArray,0,length,value,0);
|
||||
builder.clear();
|
||||
pvLongArray->toString(&builder);
|
||||
if(debug) fprintf(fd,"convert\n%s\n",builder.c_str());
|
||||
LongArrayData data;
|
||||
pvLongArray->get(0,length,data);
|
||||
LongArray_iterator iter = data.data.begin();
|
||||
if(debug) fprintf(fd,"iter [");
|
||||
for(iter=data.data.begin();iter!=data.data.end();++iter) {
|
||||
if(debug) fprintf(fd,"%lli ",(long long)*iter);
|
||||
testDiag("Check basic array operations for %s", typeid(PVT).name());
|
||||
|
||||
typename PVT::shared_pointer arr1 = static_pointer_cast<PVT>(getPVDataCreate()->createPVScalarArray(PVT::typeCode));
|
||||
typename PVT::shared_pointer arr2 = static_pointer_cast<PVT>(getPVDataCreate()->createPVScalarArray(PVT::typeCode));
|
||||
|
||||
testOk1(*arr1==*arr2);
|
||||
testOk1(*arr1==*arr1);
|
||||
testOk1(*arr1->getScalarArray()==*arr2->getScalarArray());
|
||||
|
||||
typename PVT::svector data;
|
||||
data.reserve(200);
|
||||
basicTestData<PVT>::fill(data);
|
||||
|
||||
typename PVT::const_svector cdata(freeze(data));
|
||||
|
||||
testOk1(cdata.unique());
|
||||
arr1->replace(cdata);
|
||||
testOk1(!cdata.unique());
|
||||
|
||||
{
|
||||
typename PVT::const_svector avoid;
|
||||
arr1->PVScalarArray::getAs<typename PVT::value_type>(avoid);
|
||||
testOk1(avoid.data()==cdata.data());
|
||||
testOk1(avoid.data()==arr1->view().data());
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
if(debug) fprintf(fd,"raw [");
|
||||
int64 * pdata = get(data.data);
|
||||
for(size_t i=0; i<length; i++) {
|
||||
int64 val = pdata[i];
|
||||
if(debug) fprintf(fd,"%lli ",(long long)val);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
if(debug) fprintf(fd,"direct[");
|
||||
for(size_t i=0; i<length; i++) {
|
||||
int64 val = data.data[i];
|
||||
if(debug) fprintf(fd,"%lli ",(long long)val);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
fprintf(fd,"longArray PASSED\n");
|
||||
|
||||
testOk1(arr1->getLength()==cdata.size());
|
||||
|
||||
testOk1(*arr1!=*arr2);
|
||||
|
||||
cdata.clear();
|
||||
|
||||
testOk1(hasUniqueVector<PVT>(arr1));
|
||||
|
||||
arr2->assign(*arr1);
|
||||
|
||||
testOk1(*arr1==*arr2);
|
||||
testOk1(!hasUniqueVector<PVT>(arr1));
|
||||
|
||||
arr2->swap(cdata);
|
||||
arr2->postPut();
|
||||
|
||||
testOk1(arr2->getLength()==0);
|
||||
testOk1(cdata.size()==arr1->getLength());
|
||||
|
||||
PVIntArray::const_svector idata;
|
||||
arr1->PVScalarArray::getAs<int32>(idata);
|
||||
|
||||
testOk1(idata.at(1)==10);
|
||||
|
||||
PVIntArray::svector wdata(thaw(idata));
|
||||
|
||||
wdata.at(1) = 42;
|
||||
|
||||
idata = freeze(wdata);
|
||||
|
||||
arr1->PVScalarArray::putFrom<int32>(idata);
|
||||
|
||||
testOk1(castUnsafe<PVIntArray::value_type>(arr1->view()[1])==42);
|
||||
}
|
||||
|
||||
static void ulongArray()
|
||||
static void testShare()
|
||||
{
|
||||
if(debug) fprintf(fd,"\nulongArray\n");
|
||||
PVScalarArrayPtr pvScalarArray = pvDataCreate->createPVScalarArray(pvULong);;
|
||||
PVULongArrayPtr pvULongArray = static_pointer_cast<PVULongArray>(pvScalarArray);
|
||||
ULongArray value;
|
||||
value.reserve(length);
|
||||
uint64 xxx = 0x7fffffffffffffffLL;
|
||||
for(size_t i = 0; i<length; i++) value.push_back(xxx++);
|
||||
pvULongArray->put(0,length,value,0);
|
||||
builder.clear();
|
||||
pvULongArray->toString(&builder);
|
||||
if(debug) fprintf(fd,"put\n%s\n",builder.c_str());
|
||||
convert->fromULongArray(pvScalarArray,0,length,value,0);
|
||||
builder.clear();
|
||||
pvULongArray->toString(&builder);
|
||||
if(debug) fprintf(fd,"convert\n%s\n",builder.c_str());
|
||||
ULongArrayData data;
|
||||
pvULongArray->get(0,length,data);
|
||||
ULongArray_iterator iter = data.data.begin();
|
||||
if(debug) fprintf(fd,"iter [");
|
||||
for(iter=data.data.begin();iter!=data.data.end();++iter) {
|
||||
if(debug) fprintf(fd,"%llu ",(long long unsigned)*iter);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
if(debug) fprintf(fd,"raw [");
|
||||
uint64 * pdata = get(data.data);
|
||||
for(size_t i=0; i<length; i++) {
|
||||
uint64 val = pdata[i];
|
||||
if(debug) fprintf(fd,"%llu ",(long long unsigned)val);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
if(debug) fprintf(fd,"direct[");
|
||||
for(size_t i=0; i<length; i++) {
|
||||
uint64 val = data.data[i];
|
||||
if(debug) fprintf(fd,"%llu ",(long long unsigned)val);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
fprintf(fd,"ulongArray PASSED\n");
|
||||
testDiag("Check array data sharing");
|
||||
|
||||
PVIntArrayPtr iarr = static_pointer_cast<PVIntArray>(getPVDataCreate()->createPVScalarArray(pvInt));
|
||||
PVStringArrayPtr sarr = static_pointer_cast<PVStringArray>(getPVDataCreate()->createPVScalarArray(pvString));
|
||||
|
||||
PVIntArray::const_svector idata(4, 1);
|
||||
|
||||
sarr->PVScalarArray::putFrom<int32>(idata); // copy and convert
|
||||
|
||||
testOk1(idata.unique());
|
||||
|
||||
iarr->PVScalarArray::putFrom<int32>(idata); // take a reference
|
||||
|
||||
testOk1(!idata.unique());
|
||||
|
||||
idata.clear();
|
||||
PVIntArray::const_svector cdata;
|
||||
|
||||
sarr->PVScalarArray::getAs<int32>(cdata); // copy and convert
|
||||
|
||||
testOk1(cdata.unique());
|
||||
|
||||
iarr->PVScalarArray::getAs<int32>(cdata); // take a reference
|
||||
|
||||
testOk1(!cdata.unique());
|
||||
}
|
||||
|
||||
static void floatArray()
|
||||
{
|
||||
if(debug) fprintf(fd,"\nfloatArray\n");
|
||||
PVScalarArrayPtr pvScalarArray = pvDataCreate->createPVScalarArray(pvFloat);;
|
||||
PVFloatArrayPtr pvFloatArray = static_pointer_cast<PVFloatArray>(pvScalarArray);
|
||||
FloatArray value;
|
||||
value.reserve(length);
|
||||
for(size_t i = 0; i<length; i++) value.push_back(10.0*i);
|
||||
pvFloatArray->put(0,length,value,0);
|
||||
builder.clear();
|
||||
pvFloatArray->toString(&builder);
|
||||
if(debug) fprintf(fd,"put\n%s\n",builder.c_str());
|
||||
convert->fromFloatArray(pvScalarArray,0,length,value,0);
|
||||
builder.clear();
|
||||
pvFloatArray->toString(&builder);
|
||||
if(debug) fprintf(fd,"convert\n%s\n",builder.c_str());
|
||||
FloatArrayData data;
|
||||
pvFloatArray->get(0,length,data);
|
||||
FloatArray_iterator iter = data.data.begin();
|
||||
if(debug) fprintf(fd,"iter [");
|
||||
for(iter=data.data.begin();iter!=data.data.end();++iter) {
|
||||
if(debug) fprintf(fd,"%f ",*iter);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
if(debug) fprintf(fd,"raw [");
|
||||
float * pdata = get(data.data);
|
||||
for(size_t i=0; i<length; i++) {
|
||||
float val = pdata[i];
|
||||
if(debug) fprintf(fd,"%f ",val);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
if(debug) fprintf(fd,"direct[");
|
||||
for(size_t i=0; i<length; i++) {
|
||||
float val = data.data[i];
|
||||
if(debug) fprintf(fd,"%f ",val);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
fprintf(fd,"floatArray PASSED\n");
|
||||
}
|
||||
} // end namespace
|
||||
|
||||
static void doubleArray()
|
||||
MAIN(testPVScalarArray)
|
||||
{
|
||||
if(debug) fprintf(fd,"\ndoubleArray\n");
|
||||
PVScalarArrayPtr pvScalarArray = pvDataCreate->createPVScalarArray(pvDouble);;
|
||||
PVDoubleArrayPtr pvDoubleArray = static_pointer_cast<PVDoubleArray>(pvScalarArray);
|
||||
DoubleArray value;
|
||||
value.reserve(length);
|
||||
for(size_t i = 0; i<length; i++) value.push_back(10.0*i);
|
||||
pvDoubleArray->put(0,length,value,0);
|
||||
builder.clear();
|
||||
pvDoubleArray->toString(&builder);
|
||||
if(debug) fprintf(fd,"put\n%s\n",builder.c_str());
|
||||
convert->fromDoubleArray(pvScalarArray,0,length,value,0);
|
||||
builder.clear();
|
||||
pvDoubleArray->toString(&builder);
|
||||
if(debug) fprintf(fd,"convert\n%s\n",builder.c_str());
|
||||
DoubleArrayData data;
|
||||
pvDoubleArray->get(0,length,data);
|
||||
DoubleArray_iterator iter = data.data.begin();
|
||||
if(debug) fprintf(fd,"iter [");
|
||||
for(iter=data.data.begin();iter!=data.data.end();++iter) {
|
||||
if(debug) fprintf(fd,"%lf ",*iter);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
if(debug) fprintf(fd,"raw [");
|
||||
double * pdata = get(data.data);
|
||||
for(size_t i=0; i<length; i++) {
|
||||
double val = pdata[i];
|
||||
if(debug) fprintf(fd,"%lf ",val);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
if(debug) fprintf(fd,"direct[");
|
||||
for(size_t i=0; i<length; i++) {
|
||||
double val = data.data[i];
|
||||
if(debug) fprintf(fd,"%lf ",val);
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
fprintf(fd,"doubleArray PASSED\n");
|
||||
testPlan(156);
|
||||
testFactory();
|
||||
testBasic<PVByteArray>();
|
||||
testBasic<PVUByteArray>();
|
||||
testBasic<PVIntArray>();
|
||||
testBasic<PVDoubleArray>();
|
||||
testBasic<PVStringArray>();
|
||||
testShare();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
static void stringArray()
|
||||
{
|
||||
if(debug) fprintf(fd,"\nstringArray\n");
|
||||
PVScalarArrayPtr pvScalarArray = pvDataCreate->createPVScalarArray(pvString);;
|
||||
PVStringArrayPtr pvStringArray = static_pointer_cast<PVStringArray>(pvScalarArray);
|
||||
StringArray value;
|
||||
value.reserve(length);
|
||||
for(size_t i = 0; i<length; i++) {
|
||||
char val[20];
|
||||
sprintf(val,"value%d",(int)i);
|
||||
value.push_back(val);
|
||||
}
|
||||
pvStringArray->put(0,length,value,0);
|
||||
builder.clear();
|
||||
pvStringArray->toString(&builder);
|
||||
if(debug) fprintf(fd,"put\n%s\n",builder.c_str());
|
||||
convert->fromStringArray(pvScalarArray,0,length,value,0);
|
||||
builder.clear();
|
||||
pvStringArray->toString(&builder);
|
||||
if(debug) fprintf(fd,"convert\n%s\n",builder.c_str());
|
||||
StringArrayData data;
|
||||
pvStringArray->get(0,length,data);
|
||||
StringArray_iterator iter = data.data.begin();
|
||||
if(debug) fprintf(fd,"iter [");
|
||||
for(iter=data.data.begin();iter!=data.data.end();++iter) {
|
||||
String val = *iter;
|
||||
if(debug) fprintf(fd,"%s ",val.c_str());
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
if(debug) fprintf(fd,"raw [");
|
||||
String* pdata = get(data.data);
|
||||
for(size_t i=0; i<length; i++) {
|
||||
String val = pdata[i];
|
||||
if(debug) fprintf(fd,"%s ",val.c_str());
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
if(debug) fprintf(fd,"direct[");
|
||||
for(size_t i=0; i<length; i++) {
|
||||
String val = data.data[i];
|
||||
if(debug) fprintf(fd,"%s ",val.c_str());
|
||||
}
|
||||
if(debug) fprintf(fd,"]\n");
|
||||
fprintf(fd,"stringArray PASSED\n");
|
||||
}
|
||||
|
||||
static void shareArray()
|
||||
{
|
||||
if(debug) fprintf(fd,"\nshareArray\n");
|
||||
PVScalarArrayPtr pvScalarArray = pvDataCreate->createPVScalarArray(pvDouble);;
|
||||
PVDoubleArrayPtr pvDoubleArray = static_pointer_cast<PVDoubleArray>(pvScalarArray);
|
||||
DoubleArray value;
|
||||
value.reserve(length);
|
||||
for(size_t i = 0; i<length; i++) value.push_back(10.0*i);
|
||||
pvDoubleArray->put(0,length,value,0);
|
||||
PVDoubleArrayPtr pvShareArray = static_pointer_cast<PVDoubleArray>(
|
||||
pvDataCreate->createPVScalarArray(pvDouble));
|
||||
pvShareArray->shareData(
|
||||
pvDoubleArray->getSharedVector(),
|
||||
pvDoubleArray->getCapacity(),
|
||||
pvDoubleArray->getLength());
|
||||
printf("pvDoubleArray->get() %p pvShareArray->get() %p\n",pvDoubleArray->get(),pvShareArray->get());
|
||||
printf("pvDoubleArray->getVector() %p pvShareArray->getVector() %p\n",
|
||||
&(pvDoubleArray->getVector()),&(pvShareArray->getVector()));
|
||||
printf("pvDoubleArray->getSharedVector() %p pvShareArray->getSharedVector() %p\n",
|
||||
&(pvDoubleArray->getSharedVector()),&(pvShareArray->getSharedVector()));
|
||||
assert(pvDoubleArray->get()==pvShareArray->get());
|
||||
builder.clear();
|
||||
pvShareArray->toString(&builder);
|
||||
if(debug) fprintf(fd,"pvShare\n%s\n",builder.c_str());
|
||||
fprintf(fd,"shareArray PASSED\n");
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
byteArray();
|
||||
ubyteArray();
|
||||
longArray();
|
||||
ulongArray();
|
||||
floatArray();
|
||||
doubleArray();
|
||||
stringArray();
|
||||
shareArray();
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,101 +22,138 @@
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
static bool debug = false;
|
||||
using namespace epics::pvData;
|
||||
|
||||
static FieldCreatePtr fieldCreate;
|
||||
static PVDataCreatePtr pvDataCreate;
|
||||
static StandardFieldPtr standardField;
|
||||
static StandardPVFieldPtr standardPVField;
|
||||
static ConvertPtr convert;
|
||||
static String buffer;
|
||||
|
||||
static void testPVStructureArray(FILE * fd) {
|
||||
if(debug) fprintf(fd,"/ntestPVStructureArray\n");
|
||||
StructureArrayConstPtr alarm(
|
||||
fieldCreate->createStructureArray(standardField->alarm()));
|
||||
PVStructureArrayPtr pvAlarmStructure(
|
||||
pvDataCreate->createPVStructureArray(alarm));
|
||||
PVStructurePtrArray palarms;
|
||||
size_t na=2;
|
||||
palarms.reserve(na);
|
||||
for(size_t i=0; i<na; i++) {
|
||||
palarms.push_back(
|
||||
pvDataCreate->createPVStructure(standardField->alarm()));
|
||||
}
|
||||
pvAlarmStructure->put(0,2,palarms,0);
|
||||
buffer.clear();
|
||||
pvAlarmStructure->toString(&buffer);
|
||||
if(debug) fprintf(fd,"pvAlarmStructure\n%s\n",buffer.c_str());
|
||||
PVStructureArrayPtr copy(pvDataCreate->createPVStructureArray(alarm));
|
||||
convert->copyStructureArray(pvAlarmStructure,copy);
|
||||
buffer.clear();
|
||||
copy->toString(&buffer);
|
||||
if(debug) fprintf(fd,"copy\n%s\n",buffer.c_str());
|
||||
fprintf(fd,"testPVStructureArray PASSED\n");
|
||||
}
|
||||
|
||||
static StructureConstPtr getPowerSupplyStructure() {
|
||||
String properties("alarm");
|
||||
FieldConstPtrArray fields;
|
||||
StringArray fieldNames;
|
||||
fields.reserve(3);
|
||||
fieldNames.reserve(3);
|
||||
fieldNames.push_back("voltage");
|
||||
fieldNames.push_back("power");
|
||||
fieldNames.push_back("current");
|
||||
fields.push_back(standardField->scalar(pvDouble,properties));
|
||||
fields.push_back(standardField->scalar(pvDouble,properties));
|
||||
fields.push_back(standardField->scalar(pvDouble,properties));
|
||||
StructureConstPtr structure = fieldCreate->createStructure(
|
||||
"powerSupply_t",fieldNames,fields);
|
||||
return structure;
|
||||
}
|
||||
|
||||
static void testPowerSupplyArray(FILE * fd) {
|
||||
if(debug) fprintf(fd,"/ntestPowerSupplyArray\n");
|
||||
PVStructurePtr powerSupplyArrayStruct = standardPVField->structureArray(
|
||||
getPowerSupplyStructure(),String("alarm,timeStamp"));
|
||||
PVStructureArrayPtr powerSupplyArray =
|
||||
powerSupplyArrayStruct->getStructureArrayField(String("value"));
|
||||
assert(powerSupplyArray.get()!=NULL);
|
||||
int offset = powerSupplyArray->append(5);
|
||||
if(debug) fprintf(fd,"offset %d\n",offset);
|
||||
buffer.clear();
|
||||
powerSupplyArrayStruct->toString(&buffer);
|
||||
if(debug) fprintf(fd,"after append 5\n%s\n",buffer.c_str());
|
||||
powerSupplyArray->remove(0,2);
|
||||
buffer.clear();
|
||||
powerSupplyArrayStruct->toString(&buffer);
|
||||
if(debug) fprintf(fd,"after remove(0,2)\n%s\n",buffer.c_str());
|
||||
powerSupplyArray->remove(2,1);
|
||||
buffer.clear();
|
||||
powerSupplyArrayStruct->toString(&buffer);
|
||||
if(debug) fprintf(fd,"after remove 2,1%s\n",buffer.c_str());
|
||||
powerSupplyArray->compress();
|
||||
buffer.clear();
|
||||
powerSupplyArrayStruct->toString(&buffer);
|
||||
if(debug) fprintf(fd,"after compress%s\n",buffer.c_str());
|
||||
fprintf(fd,"testPowerSupplyArray PASSED\n");
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
static void testBasic()
|
||||
{
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
testDiag("Basic structure array ops");
|
||||
|
||||
StructureArrayConstPtr alarmtype(
|
||||
fieldCreate->createStructureArray(standardField->alarm()));
|
||||
|
||||
PVStructureArrayPtr alarmarr(pvDataCreate->createPVStructureArray(alarmtype));
|
||||
|
||||
testOk1(alarmarr->getLength()==0);
|
||||
|
||||
alarmarr->setLength(5);
|
||||
|
||||
testOk1(alarmarr->getLength()==5);
|
||||
|
||||
PVStructureArray::const_svector aview = alarmarr->view();
|
||||
|
||||
testOk1(aview.size()==5);
|
||||
testOk1(aview[4].get()==NULL);
|
||||
|
||||
alarmarr->append(2);
|
||||
|
||||
testOk1(alarmarr->getLength()==7);
|
||||
|
||||
aview = alarmarr->view();
|
||||
|
||||
testOk1(aview[4].get()==NULL);
|
||||
testOk1(aview[5].get()!=NULL);
|
||||
testOk1(aview[6].get()!=NULL);
|
||||
}
|
||||
|
||||
static void testCompress()
|
||||
{
|
||||
testDiag("Test structure array compress");
|
||||
|
||||
StructureArrayConstPtr alarmtype(
|
||||
fieldCreate->createStructureArray(standardField->alarm()));
|
||||
|
||||
PVStructureArrayPtr alarmarr(pvDataCreate->createPVStructureArray(alarmtype));
|
||||
|
||||
alarmarr->setLength(5);
|
||||
|
||||
testOk1(alarmarr->getLength()==5);
|
||||
|
||||
alarmarr->compress();
|
||||
|
||||
testOk1(alarmarr->getLength()==0);
|
||||
|
||||
alarmarr->setLength(4);
|
||||
|
||||
testOk1(alarmarr->getLength()==4);
|
||||
|
||||
PVStructureArray::svector contents(10);
|
||||
|
||||
contents[2] = pvDataCreate->createPVStructure(standardField->alarm());
|
||||
contents[4] = pvDataCreate->createPVStructure(standardField->alarm());
|
||||
contents[5] = pvDataCreate->createPVStructure(standardField->alarm());
|
||||
contents[8] = pvDataCreate->createPVStructure(standardField->alarm());
|
||||
|
||||
PVStructureArray::const_svector scont(freeze(contents));
|
||||
|
||||
alarmarr->replace(scont);
|
||||
|
||||
testOk1(!scont.unique());
|
||||
testOk1(alarmarr->getLength()==10);
|
||||
|
||||
alarmarr->compress();
|
||||
|
||||
testOk1(scont.unique()); // a realloc happened
|
||||
testOk1(alarmarr->getLength()==4);
|
||||
|
||||
PVStructureArray::svector compressed(alarmarr->reuse());
|
||||
|
||||
testOk1(scont[2]==compressed[0]);
|
||||
testOk1(scont[4]==compressed[1]);
|
||||
testOk1(scont[5]==compressed[2]);
|
||||
testOk1(scont[8]==compressed[3]);
|
||||
}
|
||||
|
||||
static void testRemove()
|
||||
{
|
||||
testDiag("Test structure array remove");
|
||||
|
||||
PVStructureArray::svector contents(10);
|
||||
|
||||
for(size_t i=0; i<contents.size(); i++)
|
||||
contents[i] = pvDataCreate->createPVStructure(standardField->alarm());
|
||||
|
||||
StructureArrayConstPtr alarmtype(
|
||||
fieldCreate->createStructureArray(standardField->alarm()));
|
||||
PVStructureArrayPtr alarmarr(pvDataCreate->createPVStructureArray(alarmtype));
|
||||
|
||||
PVStructureArray::const_svector scont(freeze(contents));
|
||||
|
||||
alarmarr->replace(scont);
|
||||
|
||||
alarmarr->remove(0, 10); // all
|
||||
|
||||
testOk1(alarmarr->getLength()==0);
|
||||
|
||||
alarmarr->replace(scont);
|
||||
|
||||
alarmarr->remove(1, 1);
|
||||
|
||||
PVStructureArray::const_svector check(alarmarr->view());
|
||||
|
||||
testOk1(scont[0]==check[0]);
|
||||
testOk1(scont[2]==check[1]);
|
||||
testOk1(scont[3]==check[2]);
|
||||
}
|
||||
|
||||
MAIN(testPVStructureArray)
|
||||
{
|
||||
testPlan(0);
|
||||
testDiag("Testing structure array handling");
|
||||
fieldCreate = getFieldCreate();
|
||||
pvDataCreate = getPVDataCreate();
|
||||
standardField = getStandardField();
|
||||
standardPVField = getStandardPVField();
|
||||
convert = getConvert();
|
||||
testPVStructureArray(fd);
|
||||
testPowerSupplyArray(fd);
|
||||
return(0);
|
||||
testBasic();
|
||||
testCompress();
|
||||
testRemove();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
||||
@@ -70,14 +70,13 @@ int main(int, char **)
|
||||
StructureConstPtr structure = standardField->scalar(pvDouble, "alarm,timeStamp");
|
||||
pvStructure = standardPVField->structureArray(structure,"alarm,timeStamp");
|
||||
size_t num = 2;
|
||||
PVStructurePtrArray pvStructures;
|
||||
pvStructures.reserve(num);
|
||||
PVStructureArray::svector pvStructures(num);
|
||||
for(size_t i=0; i<num; i++) {
|
||||
pvStructures.push_back(
|
||||
pvDataCreate->createPVStructure(structure));
|
||||
pvStructures[i]=
|
||||
pvDataCreate->createPVStructure(structure);
|
||||
}
|
||||
PVStructureArrayPtr pvStructureArray = pvStructure->getStructureArrayField("value");
|
||||
pvStructureArray->put(0, num, pvStructures, 0);
|
||||
pvStructureArray->replace(freeze(pvStructures));
|
||||
builder.clear();
|
||||
pvStructure->toString(&builder);
|
||||
print("structureArrayTest");
|
||||
|
||||
Reference in New Issue
Block a user