update testSerialization

This commit is contained in:
Michael Davidsaver
2013-05-08 14:18:29 -04:00
parent eeae12e3d4
commit 3c08834377
2 changed files with 165 additions and 402 deletions

View File

@@ -22,8 +22,9 @@ testByteBuffer_SRCS += testByteBuffer.cpp
PROD_HOST += testBaseException
testBaseException_SRCS += testBaseException.cpp
PROD_HOST += testSerialization
TESTPROD += testSerialization
testSerialization_SRCS += testSerialization.cpp
TESTS += testSerialization
PROD_HOST += testTimeStamp
testTimeStamp_SRCS += testTimeStamp.cpp

View File

@@ -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,13 @@ void serializationTest(PVFieldPtr const & field) {
deserializedField->deserialize(buffer, control);
// must equal
bool isEqual = getConvert()->equals(*field,*deserializedField);
assert(isEqual);
testOk1(*field==*deserializedField);
}
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 +141,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 +205,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 +234,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(empty);
serializationTest(pv);
pv->replace(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 +336,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 +352,19 @@ 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 testStructureId(std::ostream& ofile) {
ofile<<"Testing structureID...\n";
void testStructureId() {
testDiag("Testing structureID...");
FieldCreatePtr fieldCreate = getFieldCreate();
@@ -607,15 +381,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 +403,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 +432,34 @@ 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(171);
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();
delete buffer;
@@ -705,6 +467,6 @@ int main(int argc, char *argv[]) {
delete flusher;
epicsExitCallAtExits();
return 0;
return testDone();
}