convert all tests to use epicsUnitTest
This commit is contained in:
@@ -3,7 +3,5 @@ include $(TOP)/configure/CONFIG
|
||||
DIRS += misc
|
||||
DIRS += pv
|
||||
DIRS += property
|
||||
DIRS += monitor
|
||||
DIRS += capi
|
||||
include $(TOP)/configure/RULES_DIRS
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
TOP=../..
|
||||
|
||||
include $(TOP)/configure/CONFIG
|
||||
|
||||
LIBRARY_HOST += testc
|
||||
testc_SRCS += testc.cpp
|
||||
testc_LIBS += pvData Com
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
@@ -1,97 +0,0 @@
|
||||
/* channelBase.h */
|
||||
/**
|
||||
* 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 mrk
|
||||
*/
|
||||
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
struct StructureHandle
|
||||
{
|
||||
StructureConstPtr s;
|
||||
StructureHandle(StructureConstPtr s) : s(s) {}
|
||||
};
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void * createTest()
|
||||
{
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
FieldConstPtrArray fields;
|
||||
StringArray fieldNames;
|
||||
fields.push_back(fieldCreate->createScalar(pvString));
|
||||
fields.push_back(fieldCreate->createScalarArray(pvDouble));
|
||||
fieldNames.push_back("name");
|
||||
fieldNames.push_back("value");
|
||||
StructureConstPtr s = fieldCreate->createStructure(fieldNames, fields);
|
||||
StructureHandle * sh = new StructureHandle(s);
|
||||
return (void *)sh;
|
||||
}
|
||||
|
||||
int getNumberFields(void * handle)
|
||||
{
|
||||
StructureHandle * sh = (StructureHandle *)handle;
|
||||
return sh->s->getNumberFields();
|
||||
}
|
||||
|
||||
const char * getFieldName(void * handle, int n)
|
||||
{
|
||||
StructureHandle * sh = (StructureHandle *)handle;
|
||||
return sh->s->getFieldNames()[n].c_str();
|
||||
}
|
||||
|
||||
int getFieldType(void * handle, const char * name)
|
||||
{
|
||||
StructureHandle * sh = (StructureHandle *)handle;
|
||||
/* api missing const for getField(size_t) so have to use name */
|
||||
return sh->s->getField(name)->getType();
|
||||
}
|
||||
|
||||
int getScalarType(void * handle, const char * name)
|
||||
{
|
||||
StructureHandle * sh = (StructureHandle *)handle;
|
||||
FieldConstPtr f = sh->s->getField(name);
|
||||
if(f->getType() == scalar)
|
||||
{
|
||||
ScalarConstPtr sp = std::tr1::static_pointer_cast<const Scalar>(f);
|
||||
return sp->getScalarType();
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int getElementType(void * handle, const char * name)
|
||||
{
|
||||
StructureHandle * sh = (StructureHandle *)handle;
|
||||
FieldConstPtr f = sh->s->getField(name);
|
||||
if(f->getType() == scalarArray)
|
||||
{
|
||||
ScalarArrayConstPtr sp = std::tr1::static_pointer_cast<const ScalarArray>(f);
|
||||
return sp->getElementType();
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void destroy(void * handle)
|
||||
{
|
||||
StructureHandle * sh = (StructureHandle *)handle;
|
||||
delete sh;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
from ctypes import *
|
||||
|
||||
# cytpes API
|
||||
|
||||
libname = "../../lib/%s/libtestc.so" % os.environ["EPICS_HOST_ARCH"]
|
||||
lib = CDLL(libname)
|
||||
lib.createTest.restype = c_void_p
|
||||
lib.createTest.argtypes = []
|
||||
lib.getNumberFields.restype = c_int
|
||||
lib.getNumberFields.argtypes = [c_void_p]
|
||||
lib.getFieldName.restype = c_char_p
|
||||
lib.getFieldName.argtypes = [c_void_p, c_int]
|
||||
lib.getFieldType.restype = c_int
|
||||
lib.getFieldType.argtypes = [c_void_p, c_char_p]
|
||||
lib.getScalarType.restype = c_int
|
||||
lib.getScalarType.argtypes = [c_void_p, c_char_p]
|
||||
lib.getElementType.restype = c_int
|
||||
lib.getElementType.argtypes = [c_void_p, c_char_p]
|
||||
|
||||
# Python API
|
||||
|
||||
type_enum = ["scalar", "scalarArray", "structure", "structureArray"]
|
||||
|
||||
class Structure:
|
||||
def getNumberFields(self):
|
||||
return lib.getNumberFields(self.handle)
|
||||
def getFieldName(self, n):
|
||||
return lib.getFieldName(self.handle, n)
|
||||
def getFieldType(self, n):
|
||||
return lib.getFieldType(self.handle, n)
|
||||
def getScalarType(self, n):
|
||||
return lib.getScalarType(self.handle, n)
|
||||
def getElementType(self, n):
|
||||
return lib.getElementType(self.handle, n)
|
||||
def __enter__(self):
|
||||
return self
|
||||
def __exit__(self, a, b, c):
|
||||
print "destroying handle"
|
||||
lib.destroy(self.handle)
|
||||
|
||||
class TestStructure(Structure):
|
||||
def __init__(self):
|
||||
self.handle = lib.createTest()
|
||||
|
||||
with TestStructure() as s:
|
||||
l = s.getNumberFields()
|
||||
print "pvData structure has %d fields" % l
|
||||
for n in range(l):
|
||||
name = s.getFieldName(n)
|
||||
type_ = s.getFieldType(name)
|
||||
sc_type = s.getScalarType(name)
|
||||
el_type = s.getElementType(name)
|
||||
print name, type_enum[type_], sc_type, el_type
|
||||
|
||||
@@ -6,12 +6,15 @@ PROD_LIBS += pvData Com
|
||||
|
||||
PROD_HOST += testThread
|
||||
testThread_SRCS += testThread.cpp
|
||||
TESTS += testThread
|
||||
|
||||
PROD_HOST += testTimer
|
||||
testTimer_SRCS += testTimer.cpp
|
||||
TESTS += testTimer
|
||||
|
||||
PROD_HOST += testBitSet
|
||||
testBitSet_SRCS += testBitSet.cpp
|
||||
TESTS += testBitSet
|
||||
|
||||
PROD_HOST += testOverrunBitSet
|
||||
testOverrunBitSet_SRCS += testOverrunBitSet.cpp
|
||||
@@ -22,28 +25,33 @@ testByteOrder_SRCS += testByteOrder.cpp
|
||||
|
||||
PROD_HOST += testByteBuffer
|
||||
testByteBuffer_SRCS += testByteBuffer.cpp
|
||||
TESTS += testByteBuffer
|
||||
|
||||
PROD_HOST += testBaseException
|
||||
testBaseException_SRCS += testBaseException.cpp
|
||||
TESTS += testBaseException
|
||||
|
||||
TESTPROD += testSharedVector
|
||||
PROD_HOST += testSharedVector
|
||||
testSharedVector_SRCS += testSharedVector.cpp
|
||||
TESTS += testSharedVector
|
||||
|
||||
TESTPROD += testSerialization
|
||||
PROD_HOST += testSerialization
|
||||
testSerialization_SRCS += testSerialization.cpp
|
||||
TESTS += testSerialization
|
||||
|
||||
PROD_HOST += testTimeStamp
|
||||
testTimeStamp_SRCS += testTimeStamp.cpp
|
||||
TESTS += testTimeStamp
|
||||
|
||||
PROD_HOST += testQueue
|
||||
testQueue_SRCS += testQueue.cpp
|
||||
TESTS += testQueue
|
||||
|
||||
PROD_HOST += testMessageQueue
|
||||
testMessageQueue_SRCS += testMessageQueue.cpp
|
||||
TESTS += testMessageQueue
|
||||
|
||||
TESTPROD += testTypeCast
|
||||
PROD_HOST += testTypeCast
|
||||
testTypeCast_SRCS += testTypeCast.cpp
|
||||
TESTS += testTypeCast
|
||||
|
||||
|
||||
@@ -11,11 +11,12 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/epicsException.h>
|
||||
|
||||
|
||||
#include <epicsAssert.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
struct Unroller
|
||||
@@ -41,13 +42,13 @@ void internalTestBaseException(int /*unused*/ = 0)
|
||||
}
|
||||
}
|
||||
|
||||
void testBaseException(FILE *fp) {
|
||||
fprintf(fp,"testBaseException... ");
|
||||
void testBaseException() {
|
||||
printf("testBaseException... ");
|
||||
|
||||
try {
|
||||
THROW_BASE_EXCEPTION("all is OK");
|
||||
} catch (BaseException& be) {
|
||||
fprintf(fp,"\n\n%s\n\n", be.what());
|
||||
printf("\n\n%s\n\n", be.what());
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -57,38 +58,35 @@ void testBaseException(FILE *fp) {
|
||||
THROW_BASE_EXCEPTION_CAUSE("exception 2", be2);
|
||||
}
|
||||
} catch (BaseException& be) {
|
||||
fprintf(fp,"\n\n%s\n\n", be.what());
|
||||
printf("\n\n%s\n\n", be.what());
|
||||
}
|
||||
|
||||
fprintf(fp,"PASSED\n");
|
||||
testPass("testBaseException");
|
||||
}
|
||||
|
||||
void testLogicException(FILE *fp) {
|
||||
void testLogicException() {
|
||||
try {
|
||||
THROW_EXCEPTION(std::logic_error("There is a logic_error"));
|
||||
} catch (std::logic_error& be) {
|
||||
fprintf(fp,"\n\n%s\n\n", be.what());
|
||||
PRINT_EXCEPTION2(be, fp);
|
||||
printf("\n\n%s\n\n", be.what());
|
||||
PRINT_EXCEPTION2(be, stdout);
|
||||
}
|
||||
|
||||
try {
|
||||
THROW_EXCEPTION2(std::logic_error, "There is another logic_error");
|
||||
} catch (std::logic_error& be) {
|
||||
fprintf(fp,"\n\n%s\n\n", be.what());
|
||||
fprintf(fp,"%s\n", SHOW_EXCEPTION(be).c_str());
|
||||
printf("\n\n%s\n\n", be.what());
|
||||
printf("%s\n", SHOW_EXCEPTION(be).c_str());
|
||||
}
|
||||
testPass("testLogicException");
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
MAIN(testBaseException)
|
||||
{
|
||||
FILE *fp=NULL;
|
||||
if(argc>1){
|
||||
fp=fopen(argv[1], "w");
|
||||
if(!fp) fprintf(stderr,"Failed to open test output file\n");
|
||||
}
|
||||
if(!fp) fp=stdout;
|
||||
testLogicException(fp);
|
||||
testBaseException(fp);
|
||||
return(0);
|
||||
testPlan(2);
|
||||
testDiag("Tests base exception");
|
||||
testLogicException();
|
||||
testBaseException();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
||||
@@ -14,87 +14,87 @@
|
||||
#include <stdio.h>
|
||||
#include <pv/bitSet.h>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsExit.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
void testGetSetClearFlip(FILE *fd) {
|
||||
fprintf(fd,"testGetSetClearFlip... ");
|
||||
static void testGetSetClearFlip()
|
||||
{
|
||||
printf("testGetSetClearFlip... ");
|
||||
|
||||
// empty
|
||||
BitSet* b1 = new BitSet();
|
||||
assert(b1->isEmpty());
|
||||
assert(b1->cardinality() == 0);
|
||||
testOk1(b1->isEmpty());
|
||||
testOk1(b1->cardinality() == 0);
|
||||
// to string check
|
||||
std::string str; b1->toString(&str);
|
||||
assert(str == "{}");
|
||||
testOk1(str == "{}");
|
||||
|
||||
// one
|
||||
b1->set(3);
|
||||
assert(b1->get(3));
|
||||
assert(!b1->isEmpty());
|
||||
assert(b1->cardinality() == 1);
|
||||
testOk1(b1->get(3));
|
||||
testOk1(!b1->isEmpty());
|
||||
testOk1(b1->cardinality() == 1);
|
||||
// to string check
|
||||
str.clear(); b1->toString(&str);
|
||||
assert(str == "{3}");
|
||||
testOk1(str == "{3}");
|
||||
|
||||
// grow
|
||||
b1->set(66);
|
||||
b1->set(67);
|
||||
b1->set(68);
|
||||
assert(b1->cardinality() == 4);
|
||||
testOk1(b1->cardinality() == 4);
|
||||
str.clear(); b1->toString(&str);
|
||||
assert(str == "{3, 66, 67, 68}");
|
||||
testOk1(str == "{3, 66, 67, 68}");
|
||||
|
||||
// clear one
|
||||
b1->clear(67);
|
||||
assert(b1->cardinality() == 3);
|
||||
testOk1(b1->cardinality() == 3);
|
||||
str.clear(); b1->toString(&str);
|
||||
assert(str == "{3, 66, 68}");
|
||||
testOk1(str == "{3, 66, 68}");
|
||||
|
||||
// flip
|
||||
b1->flip(66);
|
||||
b1->flip(130);
|
||||
assert(b1->cardinality() == 3);
|
||||
testOk1(b1->cardinality() == 3);
|
||||
str.clear(); b1->toString(&str);
|
||||
assert(str == "{3, 68, 130}");
|
||||
testOk1(str == "{3, 68, 130}");
|
||||
|
||||
// flip
|
||||
b1->set(130, false);
|
||||
b1->set(4, true);
|
||||
assert(b1->cardinality() == 3);
|
||||
testOk1(b1->cardinality() == 3);
|
||||
str.clear(); b1->toString(&str);
|
||||
assert(str == "{3, 4, 68}");
|
||||
testOk1(str == "{3, 4, 68}");
|
||||
|
||||
// clear all
|
||||
b1->clear();
|
||||
assert(b1->isEmpty());
|
||||
assert(b1->cardinality() == 0);
|
||||
testOk1(b1->isEmpty());
|
||||
testOk1(b1->cardinality() == 0);
|
||||
str.clear(); b1->toString(&str);
|
||||
assert(str == "{}");
|
||||
testOk1(str == "{}");
|
||||
|
||||
delete b1;
|
||||
fprintf(fd,"PASSED\n");
|
||||
|
||||
}
|
||||
|
||||
void testOperators(FILE *fd) {
|
||||
fprintf(fd,"testOperators... ");
|
||||
static void testOperators()
|
||||
{
|
||||
printf("testOperators... ");
|
||||
|
||||
BitSet b1;
|
||||
assert(b1 == b1);
|
||||
testOk1(b1 == b1);
|
||||
BitSet b2;
|
||||
assert(b1 == b2);
|
||||
testOk1(b1 == b2);
|
||||
|
||||
b1.set(1);
|
||||
assert(!(b1 == b2));
|
||||
testOk1(!(b1 == b2));
|
||||
|
||||
// different internal length, but the same
|
||||
b2.set(100);
|
||||
b2.set(1);
|
||||
b2.flip(100);
|
||||
assert(b1 == b2);
|
||||
testOk1(b1 == b2);
|
||||
|
||||
// OR test
|
||||
b2.set(65);
|
||||
@@ -102,32 +102,32 @@ void testOperators(FILE *fd) {
|
||||
b2.set(105);
|
||||
b1 |= b2;
|
||||
std::string str; b1.toString(&str);
|
||||
assert(str == "{1, 65, 105, 106}");
|
||||
testOk1(str == "{1, 65, 105, 106}");
|
||||
b1.clear();
|
||||
b1 |= b2;
|
||||
str.clear(); b1.toString(&str);
|
||||
assert(str == "{1, 65, 105, 106}");
|
||||
testOk1(str == "{1, 65, 105, 106}");
|
||||
|
||||
// AND test
|
||||
b1.set(128);
|
||||
b1 &= b2;
|
||||
assert(b1 == b2);
|
||||
testOk1(b1 == b2);
|
||||
|
||||
// XOR test
|
||||
b1.set(128);
|
||||
b1 ^= b2;
|
||||
assert(b1.cardinality() == 1 && b1.get(128) == true);
|
||||
testOk1((b1.cardinality() == 1 && b1.get(128) == true));
|
||||
b1.clear();
|
||||
b2.clear();
|
||||
b1.set(1);
|
||||
b2.set(256);
|
||||
b1 ^= b2;
|
||||
assert(b1.cardinality() == 2 && b1.get(1) == true && b1.get(256) == true);
|
||||
testOk1((b1.cardinality() == 2 && b1.get(1) == true && b1.get(256) == true));
|
||||
|
||||
|
||||
// assign
|
||||
b1 = b2;
|
||||
assert(b1 == b2);
|
||||
testOk1(b1 == b2);
|
||||
|
||||
// or_and
|
||||
b1.clear(); b1.set(2);
|
||||
@@ -135,23 +135,15 @@ void testOperators(FILE *fd) {
|
||||
BitSet b3; b3.set(128); b3.set(520);
|
||||
b1.or_and(b2, b3);
|
||||
str.clear(); b1.toString(&str);
|
||||
assert(str == "{2, 128}");
|
||||
|
||||
fprintf(fd,"PASSED\n");
|
||||
|
||||
testOk1(str == "{2, 128}");
|
||||
}
|
||||
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
MAIN(testBitSet)
|
||||
{
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
testGetSetClearFlip(fd);
|
||||
testOperators(fd);
|
||||
return(0);
|
||||
testPlan(29);
|
||||
testGetSetClearFlip();
|
||||
testOperators();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
||||
@@ -14,115 +14,115 @@
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsEndian.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/byteBuffer.h>
|
||||
#include <pv/pvIntrospect.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
using std::cout;
|
||||
|
||||
void testBasicOperations(std::ostream& ofile) {
|
||||
ofile<<"Basic operation tests...\n";
|
||||
void testBasicOperations() {
|
||||
|
||||
ByteBuffer* buff = new ByteBuffer(32);
|
||||
assert(buff->getSize()==32);
|
||||
// assert(buff->getByteOrder()==EPICS_BYTE_ORDER);
|
||||
assert(buff->getPosition()==0);
|
||||
assert(buff->getLimit()==32);
|
||||
assert(buff->getRemaining()==32);
|
||||
testOk1(buff->getSize()==32);
|
||||
// testOk1(buff->getByteOrder()==EPICS_BYTE_ORDER);
|
||||
testOk1(buff->getPosition()==0);
|
||||
testOk1(buff->getLimit()==32);
|
||||
testOk1(buff->getRemaining()==32);
|
||||
|
||||
buff->putBoolean(true);
|
||||
assert(buff->getPosition()==1);
|
||||
assert(buff->getRemaining()==31);
|
||||
testOk1(buff->getPosition()==1);
|
||||
testOk1(buff->getRemaining()==31);
|
||||
|
||||
buff->putByte(-12);
|
||||
assert(buff->getPosition()==2);
|
||||
assert(buff->getRemaining()==30);
|
||||
testOk1(buff->getPosition()==2);
|
||||
testOk1(buff->getRemaining()==30);
|
||||
|
||||
buff->putShort(10516);
|
||||
assert(buff->getPosition()==4);
|
||||
assert(buff->getRemaining()==28);
|
||||
testOk1(buff->getPosition()==4);
|
||||
testOk1(buff->getRemaining()==28);
|
||||
|
||||
buff->putInt(0x1937628B);
|
||||
assert(buff->getPosition()==8);
|
||||
assert(buff->getRemaining()==24);
|
||||
testOk1(buff->getPosition()==8);
|
||||
testOk1(buff->getRemaining()==24);
|
||||
|
||||
buff->putLong(2345678123LL);
|
||||
assert(buff->getPosition()==16);
|
||||
assert(buff->getRemaining()==16);
|
||||
testOk1(buff->getPosition()==16);
|
||||
testOk1(buff->getRemaining()==16);
|
||||
|
||||
float testFloat = 34.67;
|
||||
buff->putFloat(testFloat);
|
||||
assert(buff->getPosition()==20);
|
||||
assert(buff->getRemaining()==12);
|
||||
testOk1(buff->getPosition()==20);
|
||||
testOk1(buff->getRemaining()==12);
|
||||
|
||||
double testDouble = -512.23974;
|
||||
buff->putDouble(testDouble);
|
||||
assert(buff->getPosition()==28);
|
||||
assert(buff->getRemaining()==4);
|
||||
testOk1(buff->getPosition()==28);
|
||||
testOk1(buff->getRemaining()==4);
|
||||
|
||||
// testing direct reads
|
||||
assert(buff->getBoolean(0)==true);
|
||||
assert(buff->getByte(1)==-12);
|
||||
assert(buff->getShort(2)==10516);
|
||||
assert(buff->getInt(4)==0x1937628B);
|
||||
assert(buff->getLong(8)==2345678123LL);
|
||||
assert(buff->getFloat(16)==testFloat);
|
||||
assert(buff->getDouble(20)==testDouble);
|
||||
testOk1(buff->getBoolean(0)==true);
|
||||
testOk1(buff->getByte(1)==-12);
|
||||
testOk1(buff->getShort(2)==10516);
|
||||
testOk1(buff->getInt(4)==0x1937628B);
|
||||
testOk1(buff->getLong(8)==2345678123LL);
|
||||
testOk1(buff->getFloat(16)==testFloat);
|
||||
testOk1(buff->getDouble(20)==testDouble);
|
||||
/*
|
||||
std::size_t sp = buff->getPosition();
|
||||
buff->setPosition(0);
|
||||
assert(buff->getBoolean()==true);
|
||||
assert(buff->getByte()==-12);
|
||||
assert(buff->getShort()==10516);
|
||||
assert(buff->getInt()==0x1937628B);
|
||||
assert(buff->getLong()==2345678123LL);
|
||||
assert(buff->getFloat()==testFloat);
|
||||
assert(buff->getDouble()==testDouble);
|
||||
testOk1(buff->getBoolean()==true);
|
||||
testOk1(buff->getByte()==-12);
|
||||
testOk1(buff->getShort()==10516);
|
||||
testOk1(buff->getInt()==0x1937628B);
|
||||
testOk1(buff->getLong()==2345678123LL);
|
||||
testOk1(buff->getFloat()==testFloat);
|
||||
testOk1(buff->getDouble()==testDouble);
|
||||
buff->setPosition(sp);
|
||||
*/
|
||||
|
||||
buff->flip();
|
||||
assert(buff->getLimit()==28);
|
||||
assert(buff->getPosition()==0);
|
||||
assert(buff->getRemaining()==28);
|
||||
testOk1(buff->getLimit()==28);
|
||||
testOk1(buff->getPosition()==0);
|
||||
testOk1(buff->getRemaining()==28);
|
||||
|
||||
assert(buff->getBoolean()==true);
|
||||
assert(buff->getPosition()==1);
|
||||
testOk1(buff->getBoolean()==true);
|
||||
testOk1(buff->getPosition()==1);
|
||||
|
||||
assert(buff->getByte()==-12);
|
||||
assert(buff->getPosition()==2);
|
||||
testOk1(buff->getByte()==-12);
|
||||
testOk1(buff->getPosition()==2);
|
||||
|
||||
assert(buff->getShort()==10516);
|
||||
assert(buff->getPosition()==4);
|
||||
testOk1(buff->getShort()==10516);
|
||||
testOk1(buff->getPosition()==4);
|
||||
|
||||
assert(buff->getInt()==0x1937628B);
|
||||
assert(buff->getPosition()==8);
|
||||
testOk1(buff->getInt()==0x1937628B);
|
||||
testOk1(buff->getPosition()==8);
|
||||
|
||||
assert(buff->getLong()==2345678123LL);
|
||||
assert(buff->getPosition()==16);
|
||||
testOk1(buff->getLong()==2345678123LL);
|
||||
testOk1(buff->getPosition()==16);
|
||||
|
||||
assert(buff->getFloat()==testFloat);
|
||||
assert(buff->getPosition()==20);
|
||||
testOk1(buff->getFloat()==testFloat);
|
||||
testOk1(buff->getPosition()==20);
|
||||
|
||||
assert(buff->getDouble()==testDouble);
|
||||
assert(buff->getPosition()==28);
|
||||
testOk1(buff->getDouble()==testDouble);
|
||||
testOk1(buff->getPosition()==28);
|
||||
|
||||
buff->clear();
|
||||
assert(buff->getPosition()==0);
|
||||
assert(buff->getLimit()==32);
|
||||
assert(buff->getRemaining()==32);
|
||||
testOk1(buff->getPosition()==0);
|
||||
testOk1(buff->getLimit()==32);
|
||||
testOk1(buff->getRemaining()==32);
|
||||
|
||||
buff->setPosition(4);
|
||||
assert(buff->getPosition()==4);
|
||||
assert(buff->getLimit()==32);
|
||||
assert(buff->getRemaining()==(32-4));
|
||||
testOk1(buff->getPosition()==4);
|
||||
testOk1(buff->getLimit()==32);
|
||||
testOk1(buff->getRemaining()==(32-4));
|
||||
|
||||
buff->setPosition(13);
|
||||
assert(buff->getPosition()==13);
|
||||
assert(buff->getLimit()==32);
|
||||
assert(buff->getRemaining()==(32-13));
|
||||
testOk1(buff->getPosition()==13);
|
||||
testOk1(buff->getLimit()==32);
|
||||
testOk1(buff->getRemaining()==(32-13));
|
||||
|
||||
// testing absolute puts
|
||||
buff->clear();
|
||||
@@ -148,35 +148,35 @@ void testBasicOperations(std::ostream& ofile) {
|
||||
buff->setPosition(sp);
|
||||
*/
|
||||
buff->flip();
|
||||
assert(buff->getLimit()==28);
|
||||
assert(buff->getPosition()==0);
|
||||
assert(buff->getRemaining()==28);
|
||||
testOk1(buff->getLimit()==28);
|
||||
testOk1(buff->getPosition()==0);
|
||||
testOk1(buff->getRemaining()==28);
|
||||
|
||||
assert(buff->getBoolean()==true);
|
||||
assert(buff->getPosition()==1);
|
||||
testOk1(buff->getBoolean()==true);
|
||||
testOk1(buff->getPosition()==1);
|
||||
|
||||
assert(buff->getByte()==-12);
|
||||
assert(buff->getPosition()==2);
|
||||
testOk1(buff->getByte()==-12);
|
||||
testOk1(buff->getPosition()==2);
|
||||
|
||||
assert(buff->getShort()==10516);
|
||||
assert(buff->getPosition()==4);
|
||||
testOk1(buff->getShort()==10516);
|
||||
testOk1(buff->getPosition()==4);
|
||||
|
||||
assert(buff->getInt()==0x1937628B);
|
||||
assert(buff->getPosition()==8);
|
||||
testOk1(buff->getInt()==0x1937628B);
|
||||
testOk1(buff->getPosition()==8);
|
||||
|
||||
assert(buff->getLong()==2345678123LL);
|
||||
assert(buff->getPosition()==16);
|
||||
testOk1(buff->getLong()==2345678123LL);
|
||||
testOk1(buff->getPosition()==16);
|
||||
|
||||
assert(buff->getFloat()==testFloat);
|
||||
assert(buff->getPosition()==20);
|
||||
testOk1(buff->getFloat()==testFloat);
|
||||
testOk1(buff->getPosition()==20);
|
||||
|
||||
assert(buff->getDouble()==testDouble);
|
||||
assert(buff->getPosition()==28);
|
||||
testOk1(buff->getDouble()==testDouble);
|
||||
testOk1(buff->getPosition()==28);
|
||||
|
||||
buff->clear();
|
||||
assert(buff->getPosition()==0);
|
||||
assert(buff->getLimit()==32);
|
||||
assert(buff->getRemaining()==32);
|
||||
testOk1(buff->getPosition()==0);
|
||||
testOk1(buff->getLimit()==32);
|
||||
testOk1(buff->getRemaining()==32);
|
||||
|
||||
char src[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
|
||||
'm' };
|
||||
@@ -184,28 +184,26 @@ void testBasicOperations(std::ostream& ofile) {
|
||||
' ' };
|
||||
|
||||
buff->put(src, 2, 6);
|
||||
assert(buff->getPosition()==6);
|
||||
assert(strncmp(buff->getArray(),&src[2],6)==0);
|
||||
testOk1(buff->getPosition()==6);
|
||||
testOk1(strncmp(buff->getArray(),&src[2],6)==0);
|
||||
|
||||
buff->flip();
|
||||
assert(buff->getLimit()==6);
|
||||
assert(buff->getPosition()==0);
|
||||
assert(buff->getRemaining()==6);
|
||||
testOk1(buff->getLimit()==6);
|
||||
testOk1(buff->getPosition()==0);
|
||||
testOk1(buff->getRemaining()==6);
|
||||
|
||||
buff->get(dst, 2, 6);
|
||||
assert(buff->getLimit()==6);
|
||||
assert(buff->getPosition()==6);
|
||||
assert(strncmp(&src[2],&dst[2],6)==0);
|
||||
testOk1(buff->getLimit()==6);
|
||||
testOk1(buff->getPosition()==6);
|
||||
testOk1(strncmp(&src[2],&dst[2],6)==0);
|
||||
|
||||
ofile<<" First 10 characters of destination: >>"<<String(dst, 10)<<"<<\n";
|
||||
cout<<" First 10 characters of destination: >>"<<String(dst, 10)<<"<<\n";
|
||||
|
||||
delete buff;
|
||||
|
||||
ofile<<"!!! PASSED\n";
|
||||
}
|
||||
|
||||
void testInverseEndianness(std::ostream& ofile) {
|
||||
ofile<<"Testing inverse endianness...\n";
|
||||
void testInverseEndianness() {
|
||||
|
||||
#if EPICS_BYTE_ORDER==EPICS_ENDIAN_BIG
|
||||
ByteBuffer* buff = new ByteBuffer(32,EPICS_ENDIAN_LITTLE);
|
||||
@@ -220,30 +218,21 @@ void testInverseEndianness(std::ostream& ofile) {
|
||||
buff->putShort(0x0102);
|
||||
buff->putInt(0x0A0B0C0D);
|
||||
|
||||
assert(strncmp(buff->getArray(),refBuffer,6)==0);
|
||||
testOk1(strncmp(buff->getArray(),refBuffer,6)==0);
|
||||
|
||||
buff->flip();
|
||||
|
||||
assert(buff->getShort()==0x0102);
|
||||
assert(buff->getInt()==0x0A0B0C0D);
|
||||
testOk1(buff->getShort()==0x0102);
|
||||
testOk1(buff->getInt()==0x0A0B0C0D);
|
||||
|
||||
delete buff;
|
||||
ofile<<"!!! PASSED\n";
|
||||
}
|
||||
|
||||
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;
|
||||
testBasicOperations(*out);
|
||||
testInverseEndianness(*out);
|
||||
return (0);
|
||||
MAIN(testByteBuffer)
|
||||
{
|
||||
testPlan(82);
|
||||
testDiag("Tests byteBuffer");
|
||||
testBasicOperations();
|
||||
testInverseEndianness();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsExit.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/lock.h>
|
||||
#include <pv/timeStamp.h>
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
static void testBasic(FILE * fd,FILE *auxfd) {
|
||||
static void testBasic() {
|
||||
int queueSize = 3;
|
||||
StringArray messages;
|
||||
messages.reserve(5);
|
||||
@@ -41,53 +41,44 @@ static void testBasic(FILE * fd,FILE *auxfd) {
|
||||
bool result;
|
||||
MessageNodePtr messageNode;
|
||||
result = queue->isEmpty();
|
||||
assert(result);
|
||||
testOk1(result);
|
||||
result = queue->put(messages[0],infoMessage,true);
|
||||
assert(result);
|
||||
testOk1(result);
|
||||
result = queue->put(messages[1],infoMessage,true);
|
||||
assert(result);
|
||||
testOk1(result);
|
||||
result = queue->put(messages[2],warningMessage,true);
|
||||
assert(result);
|
||||
assert(queue->isFull());
|
||||
testOk1(result);
|
||||
testOk1(queue->isFull());
|
||||
result = queue->put(messages[3],infoMessage,true);
|
||||
assert(result==true);
|
||||
testOk1(result==true);
|
||||
messageNode = queue->get();
|
||||
assert(messageNode.get()!=NULL);
|
||||
fprintf(fd,"message %s messageType %s\n",
|
||||
testOk1(messageNode.get()!=NULL);
|
||||
printf("message %s messageType %s\n",
|
||||
messageNode->getMessage().c_str(),
|
||||
getMessageTypeName(messageNode->getMessageType()).c_str());
|
||||
assert(messageNode->getMessage().compare(messages[0])==0);
|
||||
testOk1(messageNode->getMessage().compare(messages[0])==0);
|
||||
queue->release();
|
||||
messageNode = queue->get();
|
||||
assert(messageNode.get()!=NULL);
|
||||
assert(messageNode->getMessage().compare(messages[1])==0);
|
||||
testOk1(messageNode.get()!=NULL);
|
||||
testOk1(messageNode->getMessage().compare(messages[1])==0);
|
||||
queue->release();
|
||||
messageNode = queue->get();
|
||||
assert(messageNode.get()!=NULL);
|
||||
fprintf(fd,"message %s messageType %s\n",
|
||||
testOk1(messageNode.get()!=NULL);
|
||||
printf("message %s messageType %s\n",
|
||||
messageNode->getMessage().c_str(),
|
||||
getMessageTypeName(messageNode->getMessageType()).c_str());
|
||||
assert(messageNode->getMessage().compare(messages[3])==0);
|
||||
testOk1(messageNode->getMessage().compare(messages[3])==0);
|
||||
queue->release();
|
||||
result = queue->isEmpty();
|
||||
assert(result);
|
||||
fprintf(fd,"PASSED\n");
|
||||
testOk1(result);
|
||||
printf("PASSED\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
char *auxFileName = 0;
|
||||
if(argc>2) auxFileName = argv[2];
|
||||
FILE *auxfd = stdout;
|
||||
if(auxFileName!=0 && auxFileName[0]!=0) {
|
||||
auxfd = fopen(auxFileName,"w+");
|
||||
}
|
||||
testBasic(fd,auxfd);
|
||||
return (0);
|
||||
MAIN(testMessageQueue)
|
||||
{
|
||||
testPlan(13);
|
||||
testDiag("Tests messageQueue");
|
||||
testBasic();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsExit.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <epicsThread.h>
|
||||
|
||||
#include <pv/lock.h>
|
||||
@@ -44,15 +45,14 @@ typedef std::tr1::shared_ptr<Sink> SinkPtr;
|
||||
|
||||
class Sink : public epicsThreadRunable {
|
||||
public:
|
||||
static SinkPtr create(DataQueue &queue,FILE *auxfd);
|
||||
Sink(DataQueue &queue,FILE *auxfd);
|
||||
static SinkPtr create(DataQueue &queue);
|
||||
Sink(DataQueue &queue);
|
||||
~Sink();
|
||||
void stop();
|
||||
void look();
|
||||
virtual void run();
|
||||
private:
|
||||
DataQueue &queue;
|
||||
FILE *auxfd;
|
||||
bool isStopped;
|
||||
Event *wait;
|
||||
Event *stopped;
|
||||
@@ -61,14 +61,13 @@ private:
|
||||
epicsThread *thread;
|
||||
};
|
||||
|
||||
SinkPtr Sink::create(DataQueue &queue,FILE *auxfd)
|
||||
SinkPtr Sink::create(DataQueue &queue)
|
||||
{
|
||||
return SinkPtr(new Sink(queue,auxfd));
|
||||
return SinkPtr(new Sink(queue));
|
||||
}
|
||||
|
||||
Sink::Sink(DataQueue &queue,FILE *auxfd)
|
||||
Sink::Sink(DataQueue &queue)
|
||||
: queue(queue),
|
||||
auxfd(auxfd),
|
||||
isStopped(false),
|
||||
wait(new Event()),
|
||||
stopped(new Event()),
|
||||
@@ -111,14 +110,14 @@ void Sink::run()
|
||||
waitEmpty->signal();
|
||||
break;
|
||||
}
|
||||
fprintf(auxfd," sink a %d b %d\n",data->a,data->b);
|
||||
printf(" sink a %d b %d\n",data->a,data->b);
|
||||
queue.releaseUsed(data);
|
||||
}
|
||||
}
|
||||
stopped->signal();
|
||||
}
|
||||
|
||||
static void testBasic(FILE * fd,FILE *auxfd ) {
|
||||
static void testBasic() {
|
||||
DataPtrArray dataArray;
|
||||
dataArray.reserve(numElements);
|
||||
for(int i=0; i<numElements; i++) {
|
||||
@@ -134,42 +133,33 @@ static void testBasic(FILE * fd,FILE *auxfd ) {
|
||||
queue.setUsed(data);
|
||||
data = queue.getFree();
|
||||
}
|
||||
SinkPtr sink = SinkPtr(new Sink(queue,auxfd));
|
||||
SinkPtr sink = SinkPtr(new Sink(queue));
|
||||
queue.clear();
|
||||
while(true) {
|
||||
data = queue.getFree();
|
||||
if(data.get()==NULL) break;
|
||||
fprintf(auxfd,"source a %d b %d\n",data->a,data->b);
|
||||
printf("source a %d b %d\n",data->a,data->b);
|
||||
queue.setUsed(data);
|
||||
}
|
||||
sink->look();
|
||||
// now alternate
|
||||
for(int i=0; i<numElements; i++) {
|
||||
data = queue.getFree();
|
||||
assert(data.get()!=NULL);
|
||||
fprintf(auxfd,"source a %d b %d\n",data->a,data->b);
|
||||
testOk1(data.get()!=NULL);
|
||||
printf("source a %d b %d\n",data->a,data->b);
|
||||
queue.setUsed(data);
|
||||
sink->look();
|
||||
}
|
||||
sink->stop();
|
||||
fprintf(fd,"PASSED\n");
|
||||
printf("PASSED\n");
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
char *auxFileName = 0;
|
||||
if(argc>2) auxFileName = argv[2];
|
||||
FILE *auxfd = stdout;
|
||||
if(auxFileName!=0 && auxFileName[0]!=0) {
|
||||
auxfd = fopen(auxFileName,"w+");
|
||||
}
|
||||
testBasic(fd,auxfd);
|
||||
return (0);
|
||||
MAIN(testQueue)
|
||||
{
|
||||
testPlan(5);
|
||||
testDiag("Tests queue");
|
||||
testBasic();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
#include <cstdio>
|
||||
#include <list>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsExit.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
|
||||
#include <pv/event.h>
|
||||
#include <pv/thread.h>
|
||||
@@ -38,28 +39,29 @@ public:
|
||||
FILE *out;
|
||||
bool actuallyRan;
|
||||
Event begin, end;
|
||||
Action(FILE* fp): out(fp), actuallyRan(false) {}
|
||||
Action(): actuallyRan(false) {}
|
||||
virtual void run() {
|
||||
fprintf(out, "Action waiting\n");
|
||||
printf("Action waiting\n");
|
||||
begin.signal();
|
||||
bool waited=end.wait();
|
||||
actuallyRan=true;
|
||||
fprintf(out, "Action %s\n", waited?"true":"false");
|
||||
printf("Action %s\n", waited?"true":"false");
|
||||
}
|
||||
};
|
||||
|
||||
static void testThreadRun(FILE *fd) {
|
||||
static void testThreadRun() {
|
||||
// show that we can control thread start and stop
|
||||
ActionPtr ax(new Action(fd));
|
||||
ActionPtr ax(new Action());
|
||||
{
|
||||
ThreadPtr tr(new Thread(actionName,lowPriority,ax.get()));
|
||||
bool w=ax->begin.wait();
|
||||
fprintf(fd, "main %s\n", w?"true":"false");
|
||||
fprintf(fd, "Action is %s\n", ax->actuallyRan?"true":"false");
|
||||
printf( "main %s\n", w?"true":"false");
|
||||
printf( "Action is %s\n", ax->actuallyRan?"true":"false");
|
||||
ax->end.signal();
|
||||
}
|
||||
fprintf(fd, "Action is %s\n", ax->actuallyRan?"true":"false");
|
||||
fprintf(fd,"testThreadRun PASSED\n");
|
||||
testOk1(ax->actuallyRan==true);
|
||||
printf( "Action is %s\n", ax->actuallyRan?"true":"false");
|
||||
printf("testThreadRun PASSED\n");
|
||||
}
|
||||
|
||||
class Basic;
|
||||
@@ -80,6 +82,7 @@ public:
|
||||
{
|
||||
executor->execute(getPtrSelf());
|
||||
bool result = wait.wait();
|
||||
testOk1(result==true);
|
||||
if(result==false) printf("basic::run wait returned false\n");
|
||||
}
|
||||
virtual void command()
|
||||
@@ -97,11 +100,11 @@ private:
|
||||
|
||||
typedef std::tr1::shared_ptr<Basic> BasicPtr;
|
||||
|
||||
static void testBasic(FILE *fd) {
|
||||
static void testBasic() {
|
||||
ExecutorPtr executor(new Executor(String("basic"),middlePriority));
|
||||
BasicPtr basic( new Basic(executor));
|
||||
basic->run();
|
||||
fprintf(fd,"testBasic PASSED\n");
|
||||
printf("testBasic PASSED\n");
|
||||
}
|
||||
|
||||
class MyFunc : public TimeFunctionRequester {
|
||||
@@ -126,35 +129,26 @@ typedef std::tr1::shared_ptr<MyFunc> MyFuncPtr;
|
||||
|
||||
#ifdef TESTTHREADCONTEXT
|
||||
|
||||
static void testThreadContext(FILE *fd,FILE *auxFd) {
|
||||
static void testThreadContext() {
|
||||
ExecutorPtr executor(new Executor(String("basic"),middlePriority));
|
||||
BasicPtr basic(new Basic(executor));
|
||||
MyFuncPtr myFunc(new MyFunc(basic));
|
||||
TimeFunctionPtr timeFunction(new TimeFunction(myFunc));
|
||||
double perCall = timeFunction->timeCall();
|
||||
perCall *= 1e6;
|
||||
fprintf(auxFd,"time per call %f microseconds\n",perCall);
|
||||
fprintf(fd,"testThreadContext PASSED\n");
|
||||
printf("time per call %f microseconds\n",perCall);
|
||||
printf("testThreadContext PASSED\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
testThreadRun(fd);
|
||||
testBasic(fd);
|
||||
MAIN(testThread)
|
||||
{
|
||||
testPlan(2);
|
||||
testDiag("Tests thread");
|
||||
testThreadRun();
|
||||
testBasic();
|
||||
#ifdef TESTTHREADCONTEXT
|
||||
char *auxFileName = 0;
|
||||
if(argc>2) auxFileName = argv[2];
|
||||
FILE *auxFd = stdout;
|
||||
if(auxFileName!=0 && auxFileName[0]!=0) {
|
||||
auxFd = fopen(auxFileName,"w+");
|
||||
}
|
||||
testThreadContext(fd,auxFd);
|
||||
testThreadContext();
|
||||
#endif
|
||||
return 0;
|
||||
return testDone();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
#include <ctime>
|
||||
#include <list>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/timeStamp.h>
|
||||
|
||||
@@ -27,12 +28,12 @@ using namespace epics::pvData;
|
||||
|
||||
static bool debug = false;
|
||||
|
||||
void testTimeStamp(FILE *fd,FILE *auxfd)
|
||||
void testTimeStamp()
|
||||
{
|
||||
assert(nanoSecPerSec==1000000000);
|
||||
testOk1(nanoSecPerSec==1000000000);
|
||||
TimeStamp current;
|
||||
current.getCurrent();
|
||||
fprintf(auxfd,"current %lli %i milliSec %lli\n",
|
||||
printf("current %lli %i milliSec %lli\n",
|
||||
(long long)current.getSecondsPastEpoch(),
|
||||
current.getNanoSeconds(),
|
||||
(long long)current.getMilliseconds());
|
||||
@@ -40,7 +41,7 @@ void testTimeStamp(FILE *fd,FILE *auxfd)
|
||||
current.toTime_t(tt);
|
||||
struct tm ctm;
|
||||
memcpy(&ctm,localtime(&tt),sizeof(struct tm));
|
||||
fprintf(auxfd,
|
||||
printf(
|
||||
"%4.4d.%2.2d.%2.2d %2.2d:%2.2d:%2.2d %d isDst %s\n",
|
||||
ctm.tm_year+1900,ctm.tm_mon + 1,ctm.tm_mday,
|
||||
ctm.tm_hour,ctm.tm_min,ctm.tm_sec,
|
||||
@@ -48,13 +49,13 @@ void testTimeStamp(FILE *fd,FILE *auxfd)
|
||||
(ctm.tm_isdst==0) ? "false" : "true");
|
||||
tt = time(&tt);
|
||||
current.fromTime_t(tt);
|
||||
fprintf(auxfd,"fromTime_t\ncurrent %lli %i milliSec %lli\n",
|
||||
printf("fromTime_t\ncurrent %lli %i milliSec %lli\n",
|
||||
(long long)current.getSecondsPastEpoch(),
|
||||
current.getNanoSeconds(),
|
||||
(long long)current.getMilliseconds());
|
||||
current.toTime_t(tt);
|
||||
memcpy(&ctm,localtime(&tt),sizeof(struct tm));
|
||||
fprintf(auxfd,
|
||||
printf(
|
||||
"%4.4d.%2.2d.%2.2d %2.2d:%2.2d:%2.2d %d isDst %s\n",
|
||||
ctm.tm_year+1900,ctm.tm_mon + 1,ctm.tm_mday,
|
||||
ctm.tm_hour,ctm.tm_min,ctm.tm_sec,
|
||||
@@ -66,79 +67,70 @@ void testTimeStamp(FILE *fd,FILE *auxfd)
|
||||
left.put(current.getSecondsPastEpoch(),current.getNanoSeconds());
|
||||
double diff;
|
||||
diff = TimeStamp::diff(left,right);
|
||||
if(debug) fprintf(fd,"diff %e\n",diff);
|
||||
assert(diff==0.0);
|
||||
assert((left==right));
|
||||
assert(!(left!=right));
|
||||
assert((left<=right));
|
||||
assert(!(left<right));
|
||||
assert((left>=right));
|
||||
assert(!(left>right));
|
||||
if(debug) printf("diff %e\n",diff);
|
||||
testOk1(diff==0.0);
|
||||
testOk1((left==right));
|
||||
testOk1(!(left!=right));
|
||||
testOk1((left<=right));
|
||||
testOk1(!(left<right));
|
||||
testOk1((left>=right));
|
||||
testOk1(!(left>right));
|
||||
left.put(current.getSecondsPastEpoch()+1,current.getNanoSeconds());
|
||||
diff = TimeStamp::diff(left,right);
|
||||
if(debug) fprintf(fd,"diff %e\n",diff);
|
||||
assert(diff==1.0);
|
||||
assert(!(left==right));
|
||||
assert((left!=right));
|
||||
assert(!(left<=right));
|
||||
assert(!(left<right));
|
||||
assert((left>=right));
|
||||
assert((left>right));
|
||||
if(debug) printf("diff %e\n",diff);
|
||||
testOk1(diff==1.0);
|
||||
testOk1(!(left==right));
|
||||
testOk1((left!=right));
|
||||
testOk1(!(left<=right));
|
||||
testOk1(!(left<right));
|
||||
testOk1((left>=right));
|
||||
testOk1((left>right));
|
||||
left.put(current.getSecondsPastEpoch()-1,current.getNanoSeconds());
|
||||
diff = TimeStamp::diff(left,right);
|
||||
if(debug) fprintf(fd,"diff %e\n",diff);
|
||||
assert(diff==-1.0);
|
||||
assert(!(left==right));
|
||||
assert((left!=right));
|
||||
assert((left<=right));
|
||||
assert((left<right));
|
||||
assert(!(left>=right));
|
||||
assert(!(left>right));
|
||||
if(debug) printf("diff %e\n",diff);
|
||||
testOk1(diff==-1.0);
|
||||
testOk1(!(left==right));
|
||||
testOk1((left!=right));
|
||||
testOk1((left<=right));
|
||||
testOk1((left<right));
|
||||
testOk1(!(left>=right));
|
||||
testOk1(!(left>right));
|
||||
left.put(current.getSecondsPastEpoch(),current.getNanoSeconds()-nanoSecPerSec);
|
||||
diff = TimeStamp::diff(left,right);
|
||||
if(debug) fprintf(fd,"diff %e\n",diff);
|
||||
assert(diff==-1.0);
|
||||
assert(!(left==right));
|
||||
assert((left!=right));
|
||||
assert((left<=right));
|
||||
assert((left<right));
|
||||
assert(!(left>=right));
|
||||
assert(!(left>right));
|
||||
if(debug) printf("diff %e\n",diff);
|
||||
testOk1(diff==-1.0);
|
||||
testOk1(!(left==right));
|
||||
testOk1((left!=right));
|
||||
testOk1((left<=right));
|
||||
testOk1((left<right));
|
||||
testOk1(!(left>=right));
|
||||
testOk1(!(left>right));
|
||||
left.put(current.getSecondsPastEpoch(),current.getNanoSeconds()-1);
|
||||
diff = TimeStamp::diff(left,right);
|
||||
if(debug) fprintf(fd,"diff %e\n",diff);
|
||||
assert(diff<0.0);
|
||||
assert(!(left==right));
|
||||
assert((left!=right));
|
||||
assert((left<=right));
|
||||
assert((left<right));
|
||||
assert(!(left>=right));
|
||||
assert(!(left>right));
|
||||
if(debug) printf("diff %e\n",diff);
|
||||
testOk1(diff<0.0);
|
||||
testOk1(!(left==right));
|
||||
testOk1((left!=right));
|
||||
testOk1((left<=right));
|
||||
testOk1((left<right));
|
||||
testOk1(!(left>=right));
|
||||
testOk1(!(left>right));
|
||||
left.put(current.getSecondsPastEpoch(),current.getNanoSeconds());
|
||||
left += .1;
|
||||
diff = TimeStamp::diff(left,right);
|
||||
if(debug) fprintf(fd,"diff %e\n",diff);
|
||||
if(debug) printf("diff %e\n",diff);
|
||||
left.put(current.getSecondsPastEpoch(),current.getNanoSeconds());
|
||||
int64 inc = -1;
|
||||
left += inc;
|
||||
diff = TimeStamp::diff(left,right);
|
||||
assert(diff==-1.0);
|
||||
fprintf(fd,"PASSED\n");
|
||||
testOk1(diff==-1.0);
|
||||
printf("PASSED\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
char *auxFileName = 0;
|
||||
if(argc>2) auxFileName = argv[2];
|
||||
FILE *auxfd = stdout;
|
||||
if(auxFileName!=0 && auxFileName[0]!=0) {
|
||||
auxfd = fopen(auxFileName,"w+");
|
||||
}
|
||||
testTimeStamp(fd,auxfd);
|
||||
return (0);
|
||||
MAIN(testTimeStamp)
|
||||
{
|
||||
testPlan(37);
|
||||
testDiag("Tests timeStamp");
|
||||
testTimeStamp();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsExit.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/timeStamp.h>
|
||||
#include <pv/event.h>
|
||||
#include <pv/timer.h>
|
||||
@@ -38,10 +39,8 @@ typedef std::tr1::shared_ptr<MyCallback> MyCallbackPtr;
|
||||
class MyCallback : public TimerCallback {
|
||||
public:
|
||||
POINTER_DEFINITIONS(MyCallback);
|
||||
MyCallback(String name,FILE *fd,FILE *auxfd,EventPtr const & wait)
|
||||
MyCallback(String name,EventPtr const & wait)
|
||||
: name(name),
|
||||
fd(fd),
|
||||
auxfd(auxfd),
|
||||
wait(wait)
|
||||
{
|
||||
}
|
||||
@@ -55,18 +54,16 @@ public:
|
||||
}
|
||||
virtual void timerStopped()
|
||||
{
|
||||
fprintf(fd,"timerStopped %s\n",name.c_str());
|
||||
printf("timerStopped %s\n",name.c_str());
|
||||
}
|
||||
TimeStamp &getTimeStamp() { return timeStamp;}
|
||||
private:
|
||||
String name;
|
||||
FILE *fd;
|
||||
FILE *auxfd;
|
||||
EventPtr wait;
|
||||
TimeStamp timeStamp;
|
||||
};
|
||||
|
||||
static void testBasic(FILE *fd, FILE *auxfd)
|
||||
static void testBasic()
|
||||
{
|
||||
if(debug) {
|
||||
printf("\n\ntestBasic oneDelay %lf twoDelay %lf threeDaley %lf\n",
|
||||
@@ -79,20 +76,20 @@ static void testBasic(FILE *fd, FILE *auxfd)
|
||||
EventPtr eventTwo(new Event());
|
||||
EventPtr eventThree(new Event());
|
||||
TimerPtr timer(new Timer(String("timer"),middlePriority));
|
||||
MyCallbackPtr callbackOne(new MyCallback(one,fd,auxfd,eventOne));
|
||||
MyCallbackPtr callbackTwo(new MyCallback(two,fd,auxfd,eventTwo));
|
||||
MyCallbackPtr callbackThree(new MyCallback(three,fd,auxfd,eventThree));
|
||||
MyCallbackPtr callbackOne(new MyCallback(one,eventOne));
|
||||
MyCallbackPtr callbackTwo(new MyCallback(two,eventTwo));
|
||||
MyCallbackPtr callbackThree(new MyCallback(three,eventThree));
|
||||
for(int n=0; n<ntimes; n++) {
|
||||
currentTimeStamp.getCurrent();
|
||||
assert(!timer->isScheduled(callbackOne));
|
||||
assert(!timer->isScheduled(callbackTwo));
|
||||
assert(!timer->isScheduled(callbackThree));
|
||||
testOk1(!timer->isScheduled(callbackOne));
|
||||
testOk1(!timer->isScheduled(callbackTwo));
|
||||
testOk1(!timer->isScheduled(callbackThree));
|
||||
timer->scheduleAfterDelay(callbackOne,oneDelay);
|
||||
timer->scheduleAfterDelay(callbackTwo,twoDelay);
|
||||
timer->scheduleAfterDelay(callbackThree,threeDelay);
|
||||
if(oneDelay>.1) assert(timer->isScheduled(callbackOne));
|
||||
if(twoDelay>.1) assert(timer->isScheduled(callbackTwo));
|
||||
if(threeDelay>.1) assert(timer->isScheduled(callbackThree));
|
||||
if(oneDelay>.1) testOk1(timer->isScheduled(callbackOne));
|
||||
if(twoDelay>.1) testOk1(timer->isScheduled(callbackTwo));
|
||||
if(threeDelay>.1) testOk1(timer->isScheduled(callbackThree));
|
||||
if(debug) {
|
||||
String builder;
|
||||
timer->toString(&builder);
|
||||
@@ -107,34 +104,34 @@ static void testBasic(FILE *fd, FILE *auxfd)
|
||||
callbackOne->getTimeStamp(),currentTimeStamp);
|
||||
delta = diff - oneDelay;
|
||||
if(debug) {
|
||||
fprintf(auxfd,"one requested %f actual %f delta %f\n",
|
||||
printf("one requested %f actual %f delta %f\n",
|
||||
oneDelay,diff,delta);
|
||||
}
|
||||
if(delta<0.0) delta = -delta;
|
||||
assert(delta<.1);
|
||||
testOk1(delta<.1);
|
||||
diff = TimeStamp::diff(
|
||||
callbackTwo->getTimeStamp(),currentTimeStamp);
|
||||
delta = diff - twoDelay;
|
||||
if(debug) {
|
||||
fprintf(auxfd,"two requested %f actual %f delta %f\n",
|
||||
printf("two requested %f actual %f delta %f\n",
|
||||
twoDelay,diff,delta);
|
||||
}
|
||||
if(delta<0.0) delta = -delta;
|
||||
assert(delta<.1);
|
||||
testOk1(delta<.1);
|
||||
diff = TimeStamp::diff(
|
||||
callbackThree->getTimeStamp(),currentTimeStamp);
|
||||
delta = diff - threeDelay;
|
||||
if(debug) {
|
||||
fprintf(auxfd,"three requested %f actual %f delta %f\n",
|
||||
printf("three requested %f actual %f delta %f\n",
|
||||
threeDelay,diff,delta);
|
||||
}
|
||||
if(delta<0.0) delta = -delta;
|
||||
assert(delta<.1);
|
||||
testOk1(delta<.1);
|
||||
}
|
||||
fprintf(fd,"testBasic PASSED\n");
|
||||
printf("testBasic PASSED\n");
|
||||
}
|
||||
|
||||
static void testCancel(FILE *fd, FILE *auxfd)
|
||||
static void testCancel()
|
||||
{
|
||||
if(debug) {
|
||||
printf("\n\ntestCancel oneDelay %lf twoDelay %lf threeDaley %lf\n",
|
||||
@@ -147,21 +144,21 @@ static void testCancel(FILE *fd, FILE *auxfd)
|
||||
EventPtr eventTwo(new Event());
|
||||
EventPtr eventThree(new Event());
|
||||
TimerPtr timer(new Timer(String("timer"),middlePriority));
|
||||
MyCallbackPtr callbackOne(new MyCallback(one,fd,auxfd,eventOne));
|
||||
MyCallbackPtr callbackTwo(new MyCallback(two,fd,auxfd,eventTwo));
|
||||
MyCallbackPtr callbackThree(new MyCallback(three,fd,auxfd,eventThree));
|
||||
MyCallbackPtr callbackOne(new MyCallback(one,eventOne));
|
||||
MyCallbackPtr callbackTwo(new MyCallback(two,eventTwo));
|
||||
MyCallbackPtr callbackThree(new MyCallback(three,eventThree));
|
||||
for(int n=0; n<ntimes; n++) {
|
||||
currentTimeStamp.getCurrent();
|
||||
assert(!timer->isScheduled(callbackOne));
|
||||
assert(!timer->isScheduled(callbackTwo));
|
||||
assert(!timer->isScheduled(callbackThree));
|
||||
testOk1(!timer->isScheduled(callbackOne));
|
||||
testOk1(!timer->isScheduled(callbackTwo));
|
||||
testOk1(!timer->isScheduled(callbackThree));
|
||||
timer->scheduleAfterDelay(callbackOne,oneDelay);
|
||||
timer->scheduleAfterDelay(callbackTwo,twoDelay);
|
||||
timer->scheduleAfterDelay(callbackThree,threeDelay);
|
||||
timer->cancel(callbackTwo);
|
||||
if(oneDelay>.1) assert(timer->isScheduled(callbackOne));
|
||||
assert(!timer->isScheduled(callbackTwo));
|
||||
if(threeDelay>.1) assert(timer->isScheduled(callbackThree));
|
||||
if(oneDelay>.1) testOk1(timer->isScheduled(callbackOne));
|
||||
testOk1(!timer->isScheduled(callbackTwo));
|
||||
if(threeDelay>.1) testOk1(timer->isScheduled(callbackThree));
|
||||
if(debug) {
|
||||
String builder;
|
||||
timer->toString(&builder);
|
||||
@@ -175,64 +172,55 @@ static void testCancel(FILE *fd, FILE *auxfd)
|
||||
callbackOne->getTimeStamp(),currentTimeStamp);
|
||||
delta = diff - oneDelay;
|
||||
if(debug) {
|
||||
fprintf(auxfd,"one requested %f actual %f delta %f\n",
|
||||
printf("one requested %f actual %f delta %f\n",
|
||||
oneDelay,diff,delta);
|
||||
}
|
||||
if(delta<0.0) delta = -delta;
|
||||
assert(delta<.1);
|
||||
testOk1(delta<.1);
|
||||
diff = TimeStamp::diff(
|
||||
callbackThree->getTimeStamp(),currentTimeStamp);
|
||||
delta = diff - threeDelay;
|
||||
if(debug) {
|
||||
fprintf(auxfd,"three requested %f actual %f delta %f\n",
|
||||
printf("three requested %f actual %f delta %f\n",
|
||||
threeDelay,diff,delta);
|
||||
}
|
||||
if(delta<0.0) delta = -delta;
|
||||
assert(delta<.1);
|
||||
testOk1(delta<.1);
|
||||
}
|
||||
fprintf(fd,"testCancel PASSED\n");
|
||||
printf("testCancel PASSED\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
char *auxFileName = 0;
|
||||
if(argc>2) auxFileName = argv[2];
|
||||
FILE *auxfd = stdout;
|
||||
if(auxFileName!=0 && auxFileName[0]!=0) {
|
||||
auxfd = fopen(auxFileName,"w+");
|
||||
}
|
||||
MAIN(testTimer)
|
||||
{
|
||||
testPlan(171);
|
||||
testDiag("Tests timer");
|
||||
oneDelay = .4;
|
||||
twoDelay = .2;
|
||||
threeDelay = .1;
|
||||
fprintf(fd,"oneDelay %f twoDelay %f threeDelay %f\n",
|
||||
printf("oneDelay %f twoDelay %f threeDelay %f\n",
|
||||
oneDelay,twoDelay,threeDelay);
|
||||
testBasic(fd,auxfd);
|
||||
testCancel(fd,auxfd);
|
||||
testBasic();
|
||||
testCancel();
|
||||
oneDelay = .1;
|
||||
twoDelay = .2;
|
||||
threeDelay = .4;
|
||||
fprintf(fd,"oneDelay %f twoDelay %f threeDelay %f\n",
|
||||
printf("oneDelay %f twoDelay %f threeDelay %f\n",
|
||||
oneDelay,twoDelay,threeDelay);
|
||||
testBasic(fd,auxfd);
|
||||
testCancel(fd,auxfd);
|
||||
testBasic();
|
||||
testCancel();
|
||||
oneDelay = .1;
|
||||
twoDelay = .4;
|
||||
threeDelay = .2;
|
||||
fprintf(fd,"oneDelay %f twoDelay %f threeDelay %f\n",
|
||||
printf("oneDelay %f twoDelay %f threeDelay %f\n",
|
||||
oneDelay,twoDelay,threeDelay);
|
||||
testBasic(fd,auxfd);
|
||||
testCancel(fd,auxfd);
|
||||
testBasic();
|
||||
testCancel();
|
||||
oneDelay = .0;
|
||||
twoDelay = .0;
|
||||
threeDelay = .0;
|
||||
fprintf(fd,"oneDelay %f twoDelay %f threeDelay %f\n",
|
||||
printf("oneDelay %f twoDelay %f threeDelay %f\n",
|
||||
oneDelay,twoDelay,threeDelay);
|
||||
testBasic(fd,auxfd);
|
||||
testCancel(fd,auxfd);
|
||||
return (0);
|
||||
testBasic();
|
||||
testCancel();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <float.h>
|
||||
#include <epicsMath.h>
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
TOP=../..
|
||||
|
||||
include $(TOP)/configure/CONFIG
|
||||
|
||||
PROD_HOST += testMonitor
|
||||
testMonitor_SRCS += testMonitor.cpp
|
||||
testMonitor_LIBS += pvData Com
|
||||
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
#----------------------------------------
|
||||
# ADD RULES AFTER THIS LINE
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/* testPVdata.cpp */
|
||||
/**
|
||||
* 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: Marty Kraimer Date: 2010.11 */
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsExit.h>
|
||||
|
||||
#include <pv/requester.h>
|
||||
#include <pv/pvIntrospect.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/monitor.h>
|
||||
#include <pv/standardField.h>
|
||||
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
static String allProperties("alarm,timeStamp,display,control,valueAlarm");
|
||||
static StandardFieldPtr standardField = getStandardField();
|
||||
|
||||
class MonitorImpl : public Monitor
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(MonitorImpl);
|
||||
MonitorImpl() {}
|
||||
virtual ~MonitorImpl() {}
|
||||
virtual void destroy() {}
|
||||
virtual Status start()
|
||||
{
|
||||
printf("start called\n");
|
||||
return status;
|
||||
}
|
||||
virtual Status stop()
|
||||
{
|
||||
printf("stop called\n");
|
||||
return status;
|
||||
}
|
||||
virtual MonitorElementPtr poll()
|
||||
{
|
||||
printf("poll called\n");
|
||||
return emptyElement;
|
||||
}
|
||||
virtual void release(MonitorElementPtr const & /*monitorElement*/)
|
||||
{
|
||||
printf("release called\n");
|
||||
}
|
||||
private:
|
||||
Status status;
|
||||
MonitorElementPtr emptyElement;
|
||||
};
|
||||
|
||||
static void testMonitor()
|
||||
{
|
||||
MonitorPtr monitor(new MonitorImpl());
|
||||
monitor->start();
|
||||
MonitorElementPtr monitorElement = monitor->poll();
|
||||
monitor->release(monitorElement);
|
||||
monitor->stop();
|
||||
printf("PASSED\n");
|
||||
}
|
||||
|
||||
|
||||
int main(int, char **)
|
||||
{
|
||||
testMonitor();
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@ TOP=../..
|
||||
|
||||
include $(TOP)/configure/CONFIG
|
||||
|
||||
PROD_HOST += testProperty
|
||||
TESTPROD += testProperty
|
||||
testProperty_SRCS += testProperty.cpp
|
||||
TESTS += testProperty
|
||||
|
||||
testProperty_LIBS += pvData Com
|
||||
|
||||
TESTSCRIPTS_HOST += $(TESTS:%=%.t)
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
#----------------------------------------
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsExit.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/requester.h>
|
||||
#include <pv/pvIntrospect.h>
|
||||
@@ -48,13 +48,13 @@ static String allProperties("alarm,timeStamp,display,control");
|
||||
static PVStructurePtr doubleRecord;
|
||||
static PVStructurePtr enumeratedRecord;
|
||||
|
||||
static void createRecords(FILE * fd,FILE* /*auxfd*/)
|
||||
static void createRecords()
|
||||
{
|
||||
doubleRecord = standardPVField->scalar(pvDouble,allProperties);
|
||||
if(debug) {
|
||||
builder.clear();
|
||||
doubleRecord->toString(&builder);
|
||||
fprintf(fd,"doubleRecord\n%s\n",builder.c_str());
|
||||
printf("doubleRecord\n%s\n",builder.c_str());
|
||||
}
|
||||
StringArray choices;
|
||||
choices.reserve(4);
|
||||
@@ -66,25 +66,25 @@ static void createRecords(FILE * fd,FILE* /*auxfd*/)
|
||||
if(debug) {
|
||||
builder.clear();
|
||||
enumeratedRecord->toString(&builder);
|
||||
fprintf(fd,"enumeratedRecord\n%s\n",builder.c_str());
|
||||
printf("enumeratedRecord\n%s\n",builder.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
static void printRecords(FILE * fd,FILE* /*auxfd*/)
|
||||
static void printRecords()
|
||||
{
|
||||
fprintf(fd,"doubleRecord\n");
|
||||
printf("doubleRecord\n");
|
||||
builder.clear();
|
||||
doubleRecord->toString(&builder);
|
||||
fprintf(fd,"%s\n",builder.c_str());
|
||||
fprintf(fd,"enumeratedRecord\n");
|
||||
printf("%s\n",builder.c_str());
|
||||
printf("enumeratedRecord\n");
|
||||
builder.clear();
|
||||
enumeratedRecord->toString(&builder);
|
||||
fprintf(fd,"%s\n",builder.c_str());
|
||||
printf("%s\n",builder.c_str());
|
||||
}
|
||||
|
||||
static void testAlarm(FILE * fd,FILE* /*auxfd*/)
|
||||
static void testAlarm()
|
||||
{
|
||||
if(debug) fprintf(fd,"testAlarm\n");
|
||||
if(debug) printf("testAlarm\n");
|
||||
Alarm alarm;
|
||||
PVAlarm pvAlarm;
|
||||
bool result;
|
||||
@@ -94,30 +94,30 @@ static void testAlarm(FILE * fd,FILE* /*auxfd*/)
|
||||
return;
|
||||
}
|
||||
result = pvAlarm.attach(pvField);
|
||||
assert(result);
|
||||
testOk1(result);
|
||||
Alarm al;
|
||||
al.setMessage(String("testMessage"));
|
||||
al.setSeverity(majorAlarm);
|
||||
al.setStatus(clientStatus);
|
||||
result = pvAlarm.set(al);
|
||||
assert(result);
|
||||
testOk1(result);
|
||||
pvAlarm.get(alarm);
|
||||
assert(al.getMessage().compare(alarm.getMessage())==0);
|
||||
assert(al.getSeverity()==alarm.getSeverity());
|
||||
assert(al.getStatus()==alarm.getStatus());
|
||||
testOk1(al.getMessage().compare(alarm.getMessage())==0);
|
||||
testOk1(al.getSeverity()==alarm.getSeverity());
|
||||
testOk1(al.getStatus()==alarm.getStatus());
|
||||
String message = alarm.getMessage();
|
||||
String severity = (*AlarmSeverityFunc::getSeverityNames())[alarm.getSeverity()];
|
||||
String status = (*AlarmStatusFunc::getStatusNames())[alarm.getStatus()];
|
||||
if(debug) {
|
||||
fprintf(fd," message %s severity %s status %s\n",
|
||||
printf(" message %s severity %s status %s\n",
|
||||
message.c_str(),severity.c_str(),status.c_str());
|
||||
}
|
||||
fprintf(fd,"testAlarm PASSED\n");
|
||||
printf("testAlarm PASSED\n");
|
||||
}
|
||||
|
||||
static void testTimeStamp(FILE * fd,FILE *auxfd)
|
||||
static void testTimeStamp()
|
||||
{
|
||||
if(debug) fprintf(fd,"testTimeStamp\n");
|
||||
if(debug) printf("testTimeStamp\n");
|
||||
TimeStamp timeStamp;
|
||||
PVTimeStamp pvTimeStamp;
|
||||
bool result;
|
||||
@@ -127,22 +127,22 @@ static void testTimeStamp(FILE * fd,FILE *auxfd)
|
||||
return;
|
||||
}
|
||||
result = pvTimeStamp.attach(pvField);
|
||||
assert(result);
|
||||
testOk1(result);
|
||||
TimeStamp ts;
|
||||
ts.getCurrent();
|
||||
ts.setUserTag(32);
|
||||
result = pvTimeStamp.set(ts);
|
||||
assert(result);
|
||||
testOk1(result);
|
||||
pvTimeStamp.get(timeStamp);
|
||||
assert(ts.getSecondsPastEpoch()==timeStamp.getSecondsPastEpoch());
|
||||
assert(ts.getNanoSeconds()==timeStamp.getNanoSeconds());
|
||||
assert(ts.getUserTag()==timeStamp.getUserTag());
|
||||
testOk1(ts.getSecondsPastEpoch()==timeStamp.getSecondsPastEpoch());
|
||||
testOk1(ts.getNanoSeconds()==timeStamp.getNanoSeconds());
|
||||
testOk1(ts.getUserTag()==timeStamp.getUserTag());
|
||||
time_t tt;
|
||||
timeStamp.toTime_t(tt);
|
||||
struct tm ctm;
|
||||
memcpy(&ctm,localtime(&tt),sizeof(struct tm));
|
||||
if(debug) {
|
||||
fprintf(auxfd,
|
||||
printf(
|
||||
"%4.4d.%2.2d.%2.2d %2.2d:%2.2d:%2.2d %d nanoSeconds isDst %s userTag %d\n",
|
||||
ctm.tm_year+1900,ctm.tm_mon + 1,ctm.tm_mday,
|
||||
ctm.tm_hour,ctm.tm_min,ctm.tm_sec,
|
||||
@@ -152,12 +152,12 @@ static void testTimeStamp(FILE * fd,FILE *auxfd)
|
||||
}
|
||||
timeStamp.put(0,0);
|
||||
pvTimeStamp.set(timeStamp);
|
||||
fprintf(fd,"testTimeStamp PASSED\n");
|
||||
printf("testTimeStamp PASSED\n");
|
||||
}
|
||||
|
||||
static void testControl(FILE * fd,FILE* /*auxfd*/)
|
||||
static void testControl()
|
||||
{
|
||||
if(debug) fprintf(fd,"testControl\n");
|
||||
if(debug) printf("testControl\n");
|
||||
Control control;
|
||||
PVControl pvControl;
|
||||
bool result;
|
||||
@@ -167,24 +167,24 @@ static void testControl(FILE * fd,FILE* /*auxfd*/)
|
||||
return;
|
||||
}
|
||||
result = pvControl.attach(pvField);
|
||||
assert(result);
|
||||
testOk1(result);
|
||||
Control cl;
|
||||
cl.setLow(1.0);
|
||||
cl.setHigh(10.0);
|
||||
result = pvControl.set(cl);
|
||||
assert(result);
|
||||
testOk1(result);
|
||||
pvControl.get(control);
|
||||
assert(cl.getLow()==control.getLow());
|
||||
assert(cl.getHigh()==control.getHigh());
|
||||
testOk1(cl.getLow()==control.getLow());
|
||||
testOk1(cl.getHigh()==control.getHigh());
|
||||
double low = control.getLow();
|
||||
double high = control.getHigh();
|
||||
if(debug) fprintf(fd," low %f high %f\n",low,high);
|
||||
fprintf(fd,"testControl PASSED\n");
|
||||
if(debug) printf(" low %f high %f\n",low,high);
|
||||
printf("testControl PASSED\n");
|
||||
}
|
||||
|
||||
static void testDisplay(FILE * fd,FILE* /*auxfd*/)
|
||||
static void testDisplay()
|
||||
{
|
||||
if(debug) fprintf(fd,"testDisplay\n");
|
||||
if(debug) printf("testDisplay\n");
|
||||
Display display;
|
||||
PVDisplay pvDisplay;
|
||||
bool result;
|
||||
@@ -194,7 +194,7 @@ static void testDisplay(FILE * fd,FILE* /*auxfd*/)
|
||||
return;
|
||||
}
|
||||
result = pvDisplay.attach(pvField);
|
||||
assert(result);
|
||||
testOk1(result);
|
||||
Display dy;
|
||||
dy.setLow(-10.0);
|
||||
dy.setHigh(-1.0);
|
||||
@@ -202,22 +202,22 @@ static void testDisplay(FILE * fd,FILE* /*auxfd*/)
|
||||
dy.setFormat(String("%f10.0"));
|
||||
dy.setUnits(String("volts"));
|
||||
result = pvDisplay.set(dy);
|
||||
assert(result);
|
||||
testOk1(result);
|
||||
pvDisplay.get(display);
|
||||
assert(dy.getLow()==display.getLow());
|
||||
assert(dy.getHigh()==display.getHigh());
|
||||
assert(dy.getDescription().compare(display.getDescription())==0);
|
||||
assert(dy.getFormat().compare(display.getFormat())==0);
|
||||
assert(dy.getUnits().compare(display.getUnits())==0);
|
||||
testOk1(dy.getLow()==display.getLow());
|
||||
testOk1(dy.getHigh()==display.getHigh());
|
||||
testOk1(dy.getDescription().compare(display.getDescription())==0);
|
||||
testOk1(dy.getFormat().compare(display.getFormat())==0);
|
||||
testOk1(dy.getUnits().compare(display.getUnits())==0);
|
||||
double low = display.getLow();
|
||||
double high = display.getHigh();
|
||||
if(debug) fprintf(fd," low %f high %f\n",low,high);
|
||||
fprintf(fd,"testDisplay PASSED\n");
|
||||
if(debug) printf(" low %f high %f\n",low,high);
|
||||
printf("testDisplay PASSED\n");
|
||||
}
|
||||
|
||||
static void testEnumerated(FILE * fd,FILE* /*auxfd*/)
|
||||
static void testEnumerated()
|
||||
{
|
||||
if(debug) fprintf(fd,"testEnumerated\n");
|
||||
if(debug) printf("testEnumerated\n");
|
||||
PVEnumerated pvEnumerated;
|
||||
bool result;
|
||||
PVFieldPtr pvField = enumeratedRecord->getSubField(String("value"));
|
||||
@@ -226,50 +226,39 @@ static void testEnumerated(FILE * fd,FILE* /*auxfd*/)
|
||||
return;
|
||||
}
|
||||
result = pvEnumerated.attach(pvField);
|
||||
assert(result);
|
||||
testOk1(result);
|
||||
int32 index = pvEnumerated.getIndex();
|
||||
String choice = pvEnumerated.getChoice();
|
||||
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());
|
||||
fprintf(fd,"\n");
|
||||
printf("index %d choice %s choices",index,choice.c_str());
|
||||
for(int i=0; i<numChoices; i++ ) printf(" %s",choices[i].c_str());
|
||||
printf("\n");
|
||||
}
|
||||
pvEnumerated.setIndex(2);
|
||||
index = pvEnumerated.getIndex();
|
||||
choice = pvEnumerated.getChoice();
|
||||
if(debug) fprintf(fd,"index %d choice %s\n",index,choice.c_str());
|
||||
fprintf(fd,"testEnumerated PASSED\n");
|
||||
if(debug) printf("index %d choice %s\n",index,choice.c_str());
|
||||
printf("testEnumerated PASSED\n");
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
MAIN(testProperty)
|
||||
{
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
char *auxFileName = 0;
|
||||
if(argc>2) auxFileName = argv[2];
|
||||
FILE *auxfd = stdout;
|
||||
if(auxFileName!=0 && auxFileName[0]!=0) {
|
||||
auxfd = fopen(auxFileName,"w+");
|
||||
}
|
||||
testPlan(22);
|
||||
testDiag("Tests property");
|
||||
fieldCreate = getFieldCreate();
|
||||
pvDataCreate = getPVDataCreate();
|
||||
standardField = getStandardField();
|
||||
standardPVField = getStandardPVField();
|
||||
convert = getConvert();
|
||||
createRecords(fd,auxfd);
|
||||
testAlarm(fd,auxfd);
|
||||
testTimeStamp(fd,auxfd);
|
||||
testControl(fd,auxfd);
|
||||
testDisplay(fd,auxfd);
|
||||
testEnumerated(fd,auxfd);
|
||||
if(debug) printRecords(fd,auxfd);
|
||||
fprintf(fd,"ALL PASSED\n");
|
||||
return(0);
|
||||
createRecords();
|
||||
testAlarm();
|
||||
testTimeStamp();
|
||||
testControl();
|
||||
testDisplay();
|
||||
testEnumerated();
|
||||
if(debug) printRecords();
|
||||
return testDone();;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ include $(TOP)/configure/CONFIG
|
||||
PROD_HOST += testBitSetUtil
|
||||
testBitSetUtil_SRCS += testBitSetUtil.cpp
|
||||
testBitSetUtil_LIBS += pvData Com
|
||||
TESTS += testBitSetUtil
|
||||
|
||||
PROD_HOST += testIntrospect
|
||||
testIntrospect_SRCS += testIntrospect.cpp
|
||||
@@ -14,32 +15,39 @@ TESTS += testIntrospect
|
||||
PROD_HOST += testPVAppend
|
||||
testPVAppend_SRCS += testPVAppend.cpp
|
||||
testPVAppend_LIBS += pvData Com
|
||||
TESTS += testPVAppend
|
||||
|
||||
PROD_HOST += testPVType
|
||||
testPVType_SRCS += testPVType.cpp
|
||||
testPVType_LIBS += pvData Com
|
||||
TESTS += testPVType
|
||||
|
||||
PROD_HOST += testPVAuxInfo
|
||||
testPVAuxInfo_SRCS += testPVAuxInfo.cpp
|
||||
testPVAuxInfo_LIBS += pvData Com
|
||||
TESTS += testPVAuxInfo
|
||||
|
||||
PROD_HOST += testStandardField
|
||||
testStandardField_SRCS += testStandardField.cpp
|
||||
testStandardField_LIBS += pvData Com
|
||||
TESTS += testStandardField
|
||||
|
||||
PROD_HOST += testStandardPVField
|
||||
testStandardPVField_SRCS += testStandardPVField.cpp
|
||||
testStandardPVField_LIBS += pvData Com
|
||||
TESTS += testStandardPVField
|
||||
|
||||
PROD_HOST += testPVData
|
||||
testPVData_SRCS += testPVData.cpp
|
||||
testPVData_LIBS += pvData Com
|
||||
TESTS += testPVData
|
||||
|
||||
PROD_HOST += testConvert
|
||||
testConvert_SRCS += testConvert.cpp
|
||||
testConvert_LIBS += pvData Com
|
||||
TESTS += testConvert
|
||||
|
||||
TESTPROD += testPVScalarArray
|
||||
PROD_HOST += testPVScalarArray
|
||||
testPVScalarArray_SRCS += testPVScalarArray.cpp
|
||||
testPVScalarArray_LIBS += pvData Com
|
||||
TESTS += testPVScalarArray
|
||||
@@ -52,6 +60,7 @@ TESTS += testPVStructureArray
|
||||
PROD_HOST += testOperators
|
||||
testOperators_SRCS += testOperators.cpp
|
||||
testOperators_LIBS += pvData Com
|
||||
TESTS += testOperators
|
||||
|
||||
PROD_HOST += testFieldBuilder
|
||||
testFieldBuilder_SRCS += testFieldBuilder.cpp
|
||||
|
||||
@@ -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/bitSetUtil.h>
|
||||
@@ -33,9 +33,9 @@ static StandardPVFieldPtr standardPVField;
|
||||
static ConvertPtr convert;
|
||||
static String builder("");
|
||||
|
||||
static void test(FILE * fd)
|
||||
static void test()
|
||||
{
|
||||
if(debug) fprintf(fd,"\ntestBitSetUtil\n");
|
||||
if(debug) printf("\ntestBitSetUtil\n");
|
||||
StringArray fieldNames;
|
||||
PVFieldPtrArray pvFields;
|
||||
fieldNames.reserve(5);
|
||||
@@ -62,17 +62,17 @@ static void test(FILE * fd)
|
||||
fieldNames,pvFields);
|
||||
builder.clear();
|
||||
pvs->toString(&builder);
|
||||
if(debug) fprintf(fd,"pvs\n%s\n",builder.c_str());
|
||||
if(debug) printf("pvs\n%s\n",builder.c_str());
|
||||
int32 nfields = pvs->getNumberFields();
|
||||
BitSetPtr bitSet = BitSet::create(nfields);
|
||||
for(int32 i=0; i<nfields; i++) bitSet->set(i);
|
||||
builder.clear();
|
||||
bitSet->toString(&builder);
|
||||
if(debug) fprintf(fd,"bitSet\n%s\n",builder.c_str());
|
||||
if(debug) printf("bitSet\n%s\n",builder.c_str());
|
||||
BitSetUtil::compress(bitSet,pvs);
|
||||
builder.clear();
|
||||
bitSet->toString(&builder);
|
||||
if(debug) fprintf(fd,"bitSet\n%s\n",builder.c_str());
|
||||
if(debug) printf("bitSet\n%s\n",builder.c_str());
|
||||
bitSet->clear();
|
||||
PVFieldPtr pvField = pvs->getSubField("timeStamp");
|
||||
int32 offsetTimeStamp = pvField->getFieldOffset();
|
||||
@@ -84,18 +84,18 @@ static void test(FILE * fd)
|
||||
int32 offsetUserTag = pvField->getFieldOffset();
|
||||
bitSet->set(offsetSeconds);
|
||||
BitSetUtil::compress(bitSet,pvs);
|
||||
assert(bitSet->get(offsetSeconds)==true);
|
||||
testOk1(bitSet->get(offsetSeconds)==true);
|
||||
bitSet->set(offsetNano);
|
||||
bitSet->set(offsetUserTag);
|
||||
builder.clear();
|
||||
bitSet->toString(&builder);
|
||||
if(debug) fprintf(fd,"bitSet\n%s\n",builder.c_str());
|
||||
if(debug) printf("bitSet\n%s\n",builder.c_str());
|
||||
BitSetUtil::compress(bitSet,pvs);
|
||||
assert(bitSet->get(offsetSeconds)==false);
|
||||
assert(bitSet->get(offsetTimeStamp)==true);
|
||||
testOk1(bitSet->get(offsetSeconds)==false);
|
||||
testOk1(bitSet->get(offsetTimeStamp)==true);
|
||||
builder.clear();
|
||||
bitSet->toString(&builder);
|
||||
if(debug) fprintf(fd,"bitSet\n%s\n",builder.c_str());
|
||||
if(debug) printf("bitSet\n%s\n",builder.c_str());
|
||||
bitSet->clear();
|
||||
|
||||
pvField = pvs->getSubField("current");
|
||||
@@ -116,42 +116,37 @@ static void test(FILE * fd)
|
||||
bitSet->set(offsetMessage);
|
||||
builder.clear();
|
||||
bitSet->toString(&builder);
|
||||
if(debug) fprintf(fd,"bitSet\n%s\n",builder.c_str());
|
||||
if(debug) printf("bitSet\n%s\n",builder.c_str());
|
||||
BitSetUtil::compress(bitSet,pvs);
|
||||
builder.clear();
|
||||
bitSet->toString(&builder);
|
||||
if(debug) fprintf(fd,"bitSet\n%s\n",builder.c_str());
|
||||
assert(bitSet->get(offsetCurrent)==true);
|
||||
if(debug) printf("bitSet\n%s\n",builder.c_str());
|
||||
testOk1(bitSet->get(offsetCurrent)==true);
|
||||
bitSet->clear();
|
||||
bitSet->set(offsetSeverity);
|
||||
bitSet->set(offsetStatus);
|
||||
bitSet->set(offsetMessage);
|
||||
builder.clear();
|
||||
bitSet->toString(&builder);
|
||||
if(debug) fprintf(fd,"bitSet\n%s\n",builder.c_str());
|
||||
if(debug) printf("bitSet\n%s\n",builder.c_str());
|
||||
BitSetUtil::compress(bitSet,pvs);
|
||||
builder.clear();
|
||||
bitSet->toString(&builder);
|
||||
if(debug) fprintf(fd,"bitSet\n%s\n",builder.c_str());
|
||||
assert(bitSet->get(offsetAlarm)==true);
|
||||
if(debug) printf("bitSet\n%s\n",builder.c_str());
|
||||
testOk1(bitSet->get(offsetAlarm)==true);
|
||||
bitSet->clear();
|
||||
fprintf(fd,"testBitSetUtil PASSED\n");
|
||||
printf("testBitSetUtil PASSED\n");
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
MAIN(testBitSetUtil)
|
||||
{
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
testPlan(5);
|
||||
fieldCreate = getFieldCreate();
|
||||
pvDataCreate = getPVDataCreate();
|
||||
standardField = getStandardField();
|
||||
standardPVField = getStandardPVField();
|
||||
convert = getConvert();
|
||||
test(fd);
|
||||
return(0);
|
||||
test();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
@@ -20,8 +21,9 @@ static PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
static StandardFieldPtr standardField = getStandardField();
|
||||
static StandardPVFieldPtr standardPVField = getStandardPVField();
|
||||
|
||||
int main(int, char **)
|
||||
MAIN(testOperators)
|
||||
{
|
||||
testPlan(2);
|
||||
PVStructurePtr pvStructure = standardPVField->scalar(pvDouble,
|
||||
"alarm,timeStamp,display,control,valueAlarm");
|
||||
|
||||
@@ -32,7 +34,7 @@ int main(int, char **)
|
||||
|
||||
double dv;
|
||||
*pvValue >>= dv;
|
||||
assert(testDV == dv);
|
||||
testOk1(testDV == dv);
|
||||
|
||||
|
||||
const std::string testSV = "test message";
|
||||
@@ -42,7 +44,7 @@ int main(int, char **)
|
||||
|
||||
std::string sv;
|
||||
*pvMessage >>= sv;
|
||||
assert(testSV == sv);
|
||||
testOk1(testSV == sv);
|
||||
|
||||
//
|
||||
// to stream tests
|
||||
@@ -86,6 +88,6 @@ int main(int, char **)
|
||||
pvStructureArray->replace(freeze(pvStructures));
|
||||
std::cout << *pvStructure << std::endl;
|
||||
|
||||
return 0;
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
||||
@@ -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/pvIntrospect.h>
|
||||
@@ -39,24 +39,24 @@ static String alarmTimeStampValueAlarm("alarm,timeStamp,valueAlarm");
|
||||
static String allProperties("alarm,timeStamp,display,control,valueAlarm");
|
||||
|
||||
static void checkNameAndParent(
|
||||
FILE *fd,PVStructurePtr & pvStructure, int indentLevel)
|
||||
PVStructurePtr & pvStructure, int indentLevel)
|
||||
{
|
||||
builder.clear();
|
||||
if(debug) {
|
||||
convert->newLine(&builder,indentLevel);
|
||||
fprintf(fd,"%s this %p indentLevel %d",
|
||||
printf("%s this %p indentLevel %d",
|
||||
builder.c_str(),pvStructure.get(),indentLevel);
|
||||
}
|
||||
PVFieldPtrArray pvFields = pvStructure->getPVFields();
|
||||
StringArray fieldNames = pvStructure->getStructure()->getFieldNames();
|
||||
for(size_t i = 0; i<pvFields.size(); i++) {
|
||||
PVFieldPtr pvField = pvFields[i];
|
||||
assert(pvField->getParent()==pvStructure.get());
|
||||
assert(pvField->getFieldName().compare(fieldNames[i])==0);
|
||||
testOk1(pvField->getParent()==pvStructure.get());
|
||||
testOk1(pvField->getFieldName().compare(fieldNames[i])==0);
|
||||
builder.clear();
|
||||
if(debug) {
|
||||
convert->newLine(&builder,indentLevel);
|
||||
fprintf(fd,"%s this %p name %s parent %p",
|
||||
printf("%s this %p name %s parent %p",
|
||||
builder.c_str(),
|
||||
pvField.get(),
|
||||
pvField->getFieldName().c_str(),
|
||||
@@ -64,15 +64,15 @@ static void checkNameAndParent(
|
||||
}
|
||||
if(pvField->getField()->getType()==structure) {
|
||||
PVStructurePtr xxx = static_pointer_cast<PVStructure>(pvField);
|
||||
checkNameAndParent(fd,xxx,indentLevel+1);
|
||||
checkNameAndParent(xxx,indentLevel+1);
|
||||
}
|
||||
}
|
||||
builder.clear();
|
||||
}
|
||||
|
||||
static void testAppendSimple(FILE * fd)
|
||||
static void testAppendSimple()
|
||||
{
|
||||
if(debug) fprintf(fd,"\ntestAppendSimple\n");
|
||||
if(debug) printf("\ntestAppendSimple\n");
|
||||
PVFieldPtrArray fields;
|
||||
StringArray names;
|
||||
PVStructurePtr pvParent = pvDataCreate->createPVStructure(names,fields);
|
||||
@@ -88,13 +88,13 @@ static void testAppendSimple(FILE * fd)
|
||||
pvParent->appendPVField("extra",pvField);
|
||||
builder.clear();
|
||||
pvParent->toString(&builder);
|
||||
if(debug) fprintf(fd,"%s\n",builder.c_str());
|
||||
fprintf(fd,"testAppendSimple PASSED\n");
|
||||
if(debug) printf("%s\n",builder.c_str());
|
||||
printf("testAppendSimple PASSED\n");
|
||||
}
|
||||
|
||||
static void testAppendMore(FILE * fd)
|
||||
static void testAppendMore()
|
||||
{
|
||||
if(debug) fprintf(fd,"\ntestAppendMore\n");
|
||||
if(debug) printf("\ntestAppendMore\n");
|
||||
PVFieldPtrArray fields;
|
||||
StringArray names;
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(names,fields);
|
||||
@@ -116,14 +116,14 @@ static void testAppendMore(FILE * fd)
|
||||
pvStructure->appendPVField("child2",pvField);
|
||||
builder.clear();
|
||||
pvStructure->toString(&builder);
|
||||
if(debug) fprintf(fd,"%s\n",builder.c_str());
|
||||
checkNameAndParent(fd,pvStructure,0);
|
||||
fprintf(fd,"testAppendMore PASSED\n");
|
||||
if(debug) printf("%s\n",builder.c_str());
|
||||
checkNameAndParent(pvStructure,0);
|
||||
printf("testAppendMore PASSED\n");
|
||||
}
|
||||
|
||||
static void testAppendStructures(FILE * fd)
|
||||
static void testAppendStructures()
|
||||
{
|
||||
if(debug) fprintf(fd,"\ntestAppendStructures\n");
|
||||
if(debug) printf("\ntestAppendStructures\n");
|
||||
PVFieldPtrArray fields;
|
||||
StringArray names;
|
||||
PVStructurePtr pvParent = pvDataCreate->createPVStructure(names,fields);
|
||||
@@ -141,11 +141,11 @@ static void testAppendStructures(FILE * fd)
|
||||
pvValue->appendPVField("index",pvIndex);
|
||||
builder.clear();
|
||||
pvParent->toString(&builder);
|
||||
if(debug) fprintf(fd,"%s\n",builder.c_str());
|
||||
if(debug) printf("%s\n",builder.c_str());
|
||||
builder.clear();
|
||||
pvParent->getField()->toString(&builder);
|
||||
if(debug) fprintf(fd,"field\n%s\n",builder.c_str());
|
||||
fprintf(fd,"testAppendStructures PASSED\n");
|
||||
if(debug) printf("field\n%s\n",builder.c_str());
|
||||
printf("testAppendStructures PASSED\n");
|
||||
}
|
||||
|
||||
static void append2(PVStructurePtr &pvStructure,
|
||||
@@ -168,9 +168,9 @@ static void append2(PVStructurePtr &pvStructure,
|
||||
pvFields.push_back(pvStringField);
|
||||
pvStructure->appendPVFields(names,pvFields);
|
||||
}
|
||||
static void testAppends(FILE * fd)
|
||||
static void testAppends()
|
||||
{
|
||||
if(debug) fprintf(fd,"\ntestAppends\n");
|
||||
if(debug) printf("\ntestAppends\n");
|
||||
PVFieldPtrArray emptyPVFields;
|
||||
StringArray emptyNames;
|
||||
PVFieldPtrArray pvFields;
|
||||
@@ -191,39 +191,34 @@ static void testAppends(FILE * fd)
|
||||
names,pvFields);
|
||||
builder.clear();
|
||||
pvStructure->toString(&builder);
|
||||
if(debug) fprintf(fd,"%s\n",builder.c_str());
|
||||
checkNameAndParent(fd,pvStructure,0);
|
||||
if(debug) printf("%s\n",builder.c_str());
|
||||
checkNameAndParent(pvStructure,0);
|
||||
PVFieldPtr pvField = pvStructure->getSubField("child2.Bill");
|
||||
assert(pvField.get()!=NULL);
|
||||
testOk1(pvField.get()!=NULL);
|
||||
pvField->renameField("Joe");
|
||||
builder.clear();
|
||||
pvStructure->toString(&builder);
|
||||
if(debug) fprintf(fd,"%s\n",builder.c_str());
|
||||
if(debug) printf("%s\n",builder.c_str());
|
||||
pvField->getParent()->removePVField("Joe");
|
||||
builder.clear();
|
||||
pvStructure->toString(&builder);
|
||||
if(debug) fprintf(fd,"%s\n",builder.c_str());
|
||||
checkNameAndParent(fd,pvStructure,0);
|
||||
fprintf(fd,"testAppends PASSED\n");
|
||||
if(debug) printf("%s\n",builder.c_str());
|
||||
checkNameAndParent(pvStructure,0);
|
||||
printf("testAppends PASSED\n");
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
MAIN(testPVAppend)
|
||||
{
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
testPlan(31);
|
||||
fieldCreate = getFieldCreate();
|
||||
pvDataCreate = getPVDataCreate();
|
||||
standardField = getStandardField();
|
||||
standardPVField = getStandardPVField();
|
||||
convert = getConvert();
|
||||
testAppendStructures(fd);
|
||||
testAppendSimple(fd);
|
||||
testAppendMore(fd);
|
||||
testAppends(fd);
|
||||
return(0);
|
||||
testAppendStructures();
|
||||
testAppendSimple();
|
||||
testAppendMore();
|
||||
testAppends();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
||||
@@ -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/pvIntrospect.h>
|
||||
@@ -34,9 +34,9 @@ static StandardPVFieldPtr standardPVField;
|
||||
static ConvertPtr convert;
|
||||
static String buffer;
|
||||
|
||||
static void printOffsets(PVStructurePtr pvStructure,FILE *fd)
|
||||
static void printOffsets(PVStructurePtr pvStructure)
|
||||
{
|
||||
fprintf(fd,"%s offset %lu next %lu number %lu\n",
|
||||
printf("%s offset %lu next %lu number %lu\n",
|
||||
pvStructure->getFieldName().c_str(),
|
||||
(long unsigned)pvStructure->getFieldOffset(),
|
||||
(long unsigned)pvStructure->getNextFieldOffset(),
|
||||
@@ -47,10 +47,10 @@ static void printOffsets(PVStructurePtr pvStructure,FILE *fd)
|
||||
PVFieldPtr pvField = fields[i];
|
||||
if(pvField->getField()->getType()==structure) {
|
||||
PVStructurePtr xxx = static_pointer_cast<PVStructure>(pvField);
|
||||
printOffsets(xxx,fd);
|
||||
printOffsets(xxx);
|
||||
continue;
|
||||
}
|
||||
fprintf(fd,"%s offset %lli next %lli number %lli\n",
|
||||
printf("%s offset %lli next %lli number %lli\n",
|
||||
pvField->getFieldName().c_str(),
|
||||
(long long)pvField->getFieldOffset(),
|
||||
(long long)pvField->getNextFieldOffset(),
|
||||
@@ -58,44 +58,40 @@ static void printOffsets(PVStructurePtr pvStructure,FILE *fd)
|
||||
}
|
||||
}
|
||||
|
||||
static void testPVAuxInfo(FILE * fd) {
|
||||
if(debug) fprintf(fd,"\ntestPVAuxInfo\n");
|
||||
static void testPVAuxInfo()
|
||||
{
|
||||
if(debug) printf("\ntestPVAuxInfo\n");
|
||||
PVStructurePtr pvStructure = standardPVField->scalar(
|
||||
pvDouble,"alarm,timeStamp,display,control");
|
||||
PVStructurePtr display
|
||||
= pvStructure->getStructureField("display");
|
||||
assert(display.get()!=NULL);
|
||||
testOk1(display.get()!=NULL);
|
||||
PVAuxInfoPtr auxInfo = display->getPVAuxInfo();
|
||||
auxInfo->createInfo("factory",pvString);
|
||||
auxInfo->createInfo("junk",pvDouble);
|
||||
PVScalarPtr pscalar = auxInfo->getInfo(String("factory"));
|
||||
assert(pscalar.get()!=0);
|
||||
testOk1(pscalar.get()!=0);
|
||||
convert->fromString(pscalar,"factoryName");
|
||||
pscalar = auxInfo->getInfo("junk");
|
||||
assert(pscalar.get()!=0);
|
||||
testOk1(pscalar.get()!=0);
|
||||
convert->fromString(pscalar,"3.0");
|
||||
buffer.clear();
|
||||
pvStructure->toString(&buffer);
|
||||
if(debug) fprintf(fd,"%s\n",buffer.c_str());
|
||||
if(debug) printf("%s\n",buffer.c_str());
|
||||
// now show field offsets
|
||||
if(debug) printOffsets(pvStructure,fd);
|
||||
fprintf(fd,"testPVAuxInfo PASSED\n");
|
||||
if(debug) printOffsets(pvStructure);
|
||||
printf("testPVAuxInfo PASSED\n");
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
MAIN(testPVAuxInfo)
|
||||
{
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
testPlan(3);
|
||||
fieldCreate = getFieldCreate();
|
||||
pvDataCreate = getPVDataCreate();
|
||||
standardField = getStandardField();
|
||||
standardPVField = getStandardPVField();
|
||||
convert = getConvert();
|
||||
testPVAuxInfo(fd);
|
||||
return(0);
|
||||
testPVAuxInfo();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
||||
@@ -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/pvIntrospect.h>
|
||||
@@ -37,9 +37,9 @@ static String alarmTimeStamp("alarm,timeStamp");
|
||||
static String alarmTimeStampValueAlarm("alarm,timeStamp,valueAlarm");
|
||||
static String allProperties("alarm,timeStamp,display,control,valueAlarm");
|
||||
|
||||
static void testAppend(FILE * fd)
|
||||
static void testAppend()
|
||||
{
|
||||
if(debug) fprintf(fd,"\ntestAppend\n");
|
||||
if(debug) printf("\ntestAppend\n");
|
||||
PVFieldPtrArray pvFields;
|
||||
StringArray fieldNames;
|
||||
PVStructurePtr pvParent = pvDataCreate->createPVStructure(
|
||||
@@ -51,13 +51,13 @@ static void testAppend(FILE * fd)
|
||||
pvParent->appendPVField("request",pvField);
|
||||
builder.clear();
|
||||
pvParent->toString(&builder);
|
||||
if(debug) fprintf(fd,"%s\n",builder.c_str());
|
||||
fprintf(fd,"testAppend PASSED\n");
|
||||
if(debug) printf("%s\n",builder.c_str());
|
||||
printf("testAppend PASSED\n");
|
||||
}
|
||||
|
||||
static void testCreatePVStructure(FILE * fd)
|
||||
static void testCreatePVStructure()
|
||||
{
|
||||
if(debug) fprintf(fd,"\ntestCreatePVStructure\n");
|
||||
if(debug) printf("\ntestCreatePVStructure\n");
|
||||
PVStructurePtr pv0 = standardPVField->scalar(
|
||||
pvDouble,alarmTimeStampValueAlarm);
|
||||
PVScalarPtr pv1 = pvDataCreate->createPVScalar(pvString);
|
||||
@@ -73,11 +73,11 @@ static void testCreatePVStructure(FILE * fd)
|
||||
fieldNames,pvFields);
|
||||
builder.clear();
|
||||
pvParent->toString(&builder);
|
||||
if(debug) fprintf(fd,"%s\n",builder.c_str());
|
||||
fprintf(fd,"testCreatePVStructure PASSED\n");
|
||||
if(debug) printf("%s\n",builder.c_str());
|
||||
printf("testCreatePVStructure PASSED\n");
|
||||
}
|
||||
|
||||
static void testPVScalarCommon(FILE * fd,String /*fieldName*/,ScalarType stype)
|
||||
static void testPVScalarCommon(String /*fieldName*/,ScalarType stype)
|
||||
{
|
||||
PVScalarPtr pvScalar = pvDataCreate->createPVScalar(stype);
|
||||
if(stype==pvBoolean) {
|
||||
@@ -87,11 +87,11 @@ static void testPVScalarCommon(FILE * fd,String /*fieldName*/,ScalarType stype)
|
||||
}
|
||||
builder.clear();
|
||||
pvScalar->toString(&builder);
|
||||
if(debug) fprintf(fd,"%s\n",builder.c_str());
|
||||
if(debug) printf("%s\n",builder.c_str());
|
||||
}
|
||||
|
||||
static void testPVScalarWithProperties(
|
||||
FILE * fd,String /*fieldName*/,ScalarType stype)
|
||||
String /*fieldName*/,ScalarType stype)
|
||||
{
|
||||
PVStructurePtr pvStructure;
|
||||
bool hasValueAlarm = false;
|
||||
@@ -212,45 +212,45 @@ static void testPVScalarWithProperties(
|
||||
}
|
||||
PVLongPtr seconds = pvStructure->getLongField(
|
||||
String("timeStamp.secondsPastEpoch"));
|
||||
assert(seconds!=0);
|
||||
testOk1(seconds!=0);
|
||||
seconds->put(123456789);
|
||||
PVIntPtr nano = pvStructure->getIntField(String("timeStamp.nanoSeconds"));
|
||||
assert(nano!=0);
|
||||
testOk1(nano!=0);
|
||||
nano->put(1000000);
|
||||
PVIntPtr severity = pvStructure->getIntField(String("alarm.severity"));
|
||||
assert(severity!=0);
|
||||
testOk1(severity!=0);
|
||||
severity->put(2);
|
||||
PVStringPtr message = pvStructure->getStringField(String("alarm.message"));
|
||||
assert(message!=0);
|
||||
testOk1(message!=0);
|
||||
message->put(String("messageForAlarm"));
|
||||
if(hasDisplayControl) {
|
||||
PVStringPtr desc = pvStructure->getStringField(
|
||||
String("display.description"));
|
||||
assert(desc!=0);
|
||||
testOk1(desc!=0);
|
||||
desc->put(String("this is a description"));
|
||||
PVStringPtr format = pvStructure->getStringField(
|
||||
String("display.format"));
|
||||
assert(format!=0);
|
||||
testOk1(format!=0);
|
||||
format->put(String("f10.2"));
|
||||
PVStringPtr units = pvStructure->getStringField(
|
||||
String("display.units"));
|
||||
assert(units!=0);
|
||||
testOk1(units!=0);
|
||||
units->put(String("SomeUnits"));
|
||||
PVDoublePtr limit = pvStructure->getDoubleField(
|
||||
String("display.limitLow"));
|
||||
assert(limit!=0);
|
||||
testOk1(limit!=0);
|
||||
limit->put(0.0);
|
||||
limit = pvStructure->getDoubleField(
|
||||
String("display.limitHigh"));
|
||||
assert(limit!=0);
|
||||
testOk1(limit!=0);
|
||||
limit->put(10.0);
|
||||
limit = pvStructure->getDoubleField(
|
||||
String("control.limitLow"));
|
||||
assert(limit!=0);
|
||||
testOk1(limit!=0);
|
||||
limit->put(1.0);
|
||||
limit = pvStructure->getDoubleField(
|
||||
String("control.limitHigh"));
|
||||
assert(limit!=0);
|
||||
testOk1(limit!=0);
|
||||
limit->put(9.0);
|
||||
}
|
||||
if(hasValueAlarm) {
|
||||
@@ -261,24 +261,24 @@ static void testPVScalarWithProperties(
|
||||
pvField = pvStructure->getSubField(
|
||||
String("valueAlarm.lowAlarmLimit"));
|
||||
PVScalarPtr pvtemp = static_pointer_cast<PVScalar>(pvField);
|
||||
assert(pvtemp.get()!=0);
|
||||
testOk1(pvtemp.get()!=0);
|
||||
convert->fromDouble(pvtemp,1.0);
|
||||
pvField = pvStructure->getSubField(
|
||||
String("valueAlarm.highAlarmLimit"));
|
||||
pvtemp = static_pointer_cast<PVScalar>(pvField);
|
||||
assert(pvtemp.get()!=0);
|
||||
testOk1(pvtemp.get()!=0);
|
||||
convert->fromDouble(pvtemp,9.0);
|
||||
severity = pvStructure->getIntField(
|
||||
String("valueAlarm.lowAlarmSeverity"));
|
||||
assert(severity!=0);
|
||||
testOk1(severity!=0);
|
||||
severity->put(2);
|
||||
severity = pvStructure->getIntField(
|
||||
String("valueAlarm.highAlarmSeverity"));
|
||||
assert(severity!=0);
|
||||
testOk1(severity!=0);
|
||||
severity->put(2);
|
||||
PVBooleanPtr active = pvStructure->getBooleanField(
|
||||
String("valueAlarm.active"));
|
||||
assert(active!=0);
|
||||
testOk1(active!=0);
|
||||
active->put(true);
|
||||
}
|
||||
if(hasBooleanAlarm) {
|
||||
@@ -288,60 +288,61 @@ static void testPVScalarWithProperties(
|
||||
pvBoolean->put(true);
|
||||
severity = pvStructure->getIntField(
|
||||
String("valueAlarm.falseSeverity"));
|
||||
assert(severity!=0);
|
||||
testOk1(severity!=0);
|
||||
severity->put(0);
|
||||
severity = pvStructure->getIntField(
|
||||
String("valueAlarm.trueSeverity"));
|
||||
assert(severity!=0);
|
||||
testOk1(severity!=0);
|
||||
severity->put(2);
|
||||
severity = pvStructure->getIntField(
|
||||
String("valueAlarm.changeStateSeverity"));
|
||||
assert(severity!=0);
|
||||
testOk1(severity!=0);
|
||||
severity->put(1);
|
||||
}
|
||||
builder.clear();
|
||||
pvStructure->toString(&builder);
|
||||
if(debug) fprintf(fd,"%s\n",builder.c_str());
|
||||
if(debug) printf("%s\n",builder.c_str());
|
||||
}
|
||||
|
||||
static void testPVScalar(FILE * fd) {
|
||||
if(debug) fprintf(fd,"\ntestScalar\n");
|
||||
testPVScalarCommon(fd,String("boolean"),pvByte);
|
||||
testPVScalarCommon(fd,String("byte"),pvByte);
|
||||
testPVScalarCommon(fd,String("short"),pvShort);
|
||||
testPVScalarCommon(fd,String("int"),pvInt);
|
||||
testPVScalarCommon(fd,String("long"),pvLong);
|
||||
testPVScalarCommon(fd,String("ubyte"),pvUByte);
|
||||
testPVScalarCommon(fd,String("ushort"),pvUShort);
|
||||
testPVScalarCommon(fd,String("uint"),pvUInt);
|
||||
testPVScalarCommon(fd,String("ulong"),pvULong);
|
||||
testPVScalarCommon(fd,String("float"),pvFloat);
|
||||
testPVScalarCommon(fd,String("double"),pvDouble);
|
||||
testPVScalarCommon(fd,String("string"),pvString);
|
||||
static void testPVScalar()
|
||||
{
|
||||
if(debug) printf("\ntestScalar\n");
|
||||
testPVScalarCommon(String("boolean"),pvByte);
|
||||
testPVScalarCommon(String("byte"),pvByte);
|
||||
testPVScalarCommon(String("short"),pvShort);
|
||||
testPVScalarCommon(String("int"),pvInt);
|
||||
testPVScalarCommon(String("long"),pvLong);
|
||||
testPVScalarCommon(String("ubyte"),pvUByte);
|
||||
testPVScalarCommon(String("ushort"),pvUShort);
|
||||
testPVScalarCommon(String("uint"),pvUInt);
|
||||
testPVScalarCommon(String("ulong"),pvULong);
|
||||
testPVScalarCommon(String("float"),pvFloat);
|
||||
testPVScalarCommon(String("double"),pvDouble);
|
||||
testPVScalarCommon(String("string"),pvString);
|
||||
|
||||
testPVScalarWithProperties(fd,String("boolean"),pvBoolean);
|
||||
testPVScalarWithProperties(fd,String("byte"),pvByte);
|
||||
testPVScalarWithProperties(fd,String("short"),pvShort);
|
||||
testPVScalarWithProperties(fd,String("int"),pvInt);
|
||||
testPVScalarWithProperties(fd,String("long"),pvLong);
|
||||
testPVScalarWithProperties(fd,String("ubyte"),pvUByte);
|
||||
testPVScalarWithProperties(fd,String("ushort"),pvUShort);
|
||||
testPVScalarWithProperties(fd,String("uint"),pvUInt);
|
||||
testPVScalarWithProperties(fd,String("ulong"),pvULong);
|
||||
testPVScalarWithProperties(fd,String("float"),pvFloat);
|
||||
testPVScalarWithProperties(fd,String("double"),pvDouble);
|
||||
testPVScalarWithProperties(fd,String("string"),pvString);
|
||||
fprintf(fd,"testScalar PASSED\n");
|
||||
testPVScalarWithProperties(String("boolean"),pvBoolean);
|
||||
testPVScalarWithProperties(String("byte"),pvByte);
|
||||
testPVScalarWithProperties(String("short"),pvShort);
|
||||
testPVScalarWithProperties(String("int"),pvInt);
|
||||
testPVScalarWithProperties(String("long"),pvLong);
|
||||
testPVScalarWithProperties(String("ubyte"),pvUByte);
|
||||
testPVScalarWithProperties(String("ushort"),pvUShort);
|
||||
testPVScalarWithProperties(String("uint"),pvUInt);
|
||||
testPVScalarWithProperties(String("ulong"),pvULong);
|
||||
testPVScalarWithProperties(String("float"),pvFloat);
|
||||
testPVScalarWithProperties(String("double"),pvDouble);
|
||||
testPVScalarWithProperties(String("string"),pvString);
|
||||
printf("testScalar PASSED\n");
|
||||
}
|
||||
|
||||
|
||||
static void testScalarArrayCommon(FILE * fd,String /*fieldName*/,ScalarType stype)
|
||||
static void testScalarArrayCommon(String /*fieldName*/,ScalarType stype)
|
||||
{
|
||||
PVStructurePtr pvStructure = standardPVField->scalarArray(
|
||||
stype,alarmTimeStamp);
|
||||
PVScalarArrayPtr scalarArray = pvStructure->getScalarArrayField(
|
||||
"value",stype);
|
||||
assert(scalarArray.get()!=0);
|
||||
testOk1(scalarArray.get()!=0);
|
||||
if(stype==pvBoolean) {
|
||||
StringArray values(3);
|
||||
values[0] = "true";
|
||||
@@ -357,41 +358,37 @@ static void testScalarArrayCommon(FILE * fd,String /*fieldName*/,ScalarType styp
|
||||
}
|
||||
builder.clear();
|
||||
pvStructure->toString(&builder);
|
||||
if(debug) fprintf(fd,"%s\n",builder.c_str());
|
||||
if(debug) printf("%s\n",builder.c_str());
|
||||
PVFieldPtr pvField = pvStructure->getSubField("alarm.status");
|
||||
pvField->message("this is a test",infoMessage);
|
||||
}
|
||||
|
||||
static void testScalarArray(FILE * fd) {
|
||||
if(debug) fprintf(fd,"\ntestScalarArray\n");
|
||||
testScalarArrayCommon(fd,String("boolean"),pvBoolean);
|
||||
testScalarArrayCommon(fd,String("byte"),pvByte);
|
||||
testScalarArrayCommon(fd,String("short"),pvShort);
|
||||
testScalarArrayCommon(fd,String("int"),pvInt);
|
||||
testScalarArrayCommon(fd,String("long"),pvLong);
|
||||
testScalarArrayCommon(fd,String("float"),pvFloat);
|
||||
testScalarArrayCommon(fd,String("double"),pvDouble);
|
||||
testScalarArrayCommon(fd,String("string"),pvString);
|
||||
fprintf(fd,"testScalarArray PASSED\n");
|
||||
static void testScalarArray()
|
||||
{
|
||||
if(debug) printf("\ntestScalarArray\n");
|
||||
testScalarArrayCommon(String("boolean"),pvBoolean);
|
||||
testScalarArrayCommon(String("byte"),pvByte);
|
||||
testScalarArrayCommon(String("short"),pvShort);
|
||||
testScalarArrayCommon(String("int"),pvInt);
|
||||
testScalarArrayCommon(String("long"),pvLong);
|
||||
testScalarArrayCommon(String("float"),pvFloat);
|
||||
testScalarArrayCommon(String("double"),pvDouble);
|
||||
testScalarArrayCommon(String("string"),pvString);
|
||||
printf("testScalarArray PASSED\n");
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
MAIN(testPVData)
|
||||
{
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
testPlan(179);
|
||||
fieldCreate = getFieldCreate();
|
||||
pvDataCreate = getPVDataCreate();
|
||||
standardField = getStandardField();
|
||||
standardPVField = getStandardPVField();
|
||||
convert = getConvert();
|
||||
testAppend(fd);
|
||||
testCreatePVStructure(fd);
|
||||
testPVScalar(fd);
|
||||
testScalarArray(fd);
|
||||
return(0);
|
||||
testAppend();
|
||||
testCreatePVStructure();
|
||||
testPVScalar();
|
||||
testScalarArray();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,62 +12,58 @@
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/requester.h>
|
||||
#include <pv/pvType.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
MAIN(testPVType)
|
||||
{
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
assert(sizeof(int8)==1);
|
||||
assert(sizeof(int16)==2);
|
||||
assert(sizeof(int32)==4);
|
||||
assert(sizeof(int64)==8);
|
||||
assert(sizeof(uint32)==4);
|
||||
assert(sizeof(uint64)==8);
|
||||
testPlan(6);
|
||||
testOk1(sizeof(int8)==1);
|
||||
testOk1(sizeof(int16)==2);
|
||||
testOk1(sizeof(int32)==4);
|
||||
testOk1(sizeof(int64)==8);
|
||||
testOk1(sizeof(uint32)==4);
|
||||
testOk1(sizeof(uint64)==8);
|
||||
|
||||
int intValue;
|
||||
int8 byteInt;
|
||||
intValue = 0x7f;
|
||||
byteInt = intValue;
|
||||
fprintf(fd,"int8 max %d",(int)byteInt);
|
||||
printf("int8 max %d",(int)byteInt);
|
||||
intValue = 0x80;
|
||||
byteInt = intValue;
|
||||
fprintf(fd," min %d\n",(int)byteInt);
|
||||
printf(" min %d\n",(int)byteInt);
|
||||
|
||||
int16 shortInt;
|
||||
intValue = 0x7fff;
|
||||
shortInt = intValue;
|
||||
fprintf(fd,"int8 max %hd",shortInt);
|
||||
printf("int8 max %hd",shortInt);
|
||||
intValue = 0x8000;
|
||||
shortInt = intValue;
|
||||
fprintf(fd," min %hd\n",shortInt);
|
||||
printf(" min %hd\n",shortInt);
|
||||
|
||||
int32 intInt;
|
||||
intValue = 0x7fffffff;
|
||||
intInt = intValue;
|
||||
fprintf(fd,"int8 max %d",intInt);
|
||||
printf("int8 max %d",intInt);
|
||||
intValue = 0x80000000;
|
||||
intInt = intValue;
|
||||
fprintf(fd," min %d\n",intInt);
|
||||
printf(" min %d\n",intInt);
|
||||
|
||||
int64 longInt = 0x7fffffff;
|
||||
longInt <<= 32;
|
||||
longInt |= 0xffffffff;
|
||||
fprintf(fd,"int8 max %lli",(long long)longInt);
|
||||
printf("int8 max %lli",(long long)longInt);
|
||||
longInt = intValue = 0x80000000;;
|
||||
longInt <<= 32;
|
||||
fprintf(fd," min %lli\n",(long long)longInt);
|
||||
printf(" min %lli\n",(long long)longInt);
|
||||
|
||||
fprintf(fd,"PASSED\n");
|
||||
return(0);
|
||||
printf("PASSED\n");
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
||||
@@ -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/pvIntrospect.h>
|
||||
@@ -35,8 +35,9 @@ static void print(String name)
|
||||
if(debug) printf("\n%s\n%s\n",name.c_str(),builder.c_str());
|
||||
}
|
||||
|
||||
int main(int, char **)
|
||||
MAIN(testStandardField)
|
||||
{
|
||||
testPlan(1);
|
||||
StructureConstPtr doubleValue = standardField->scalar(pvDouble,
|
||||
"alarm,timeStamp,display,control,valueAlarm");
|
||||
builder.clear();
|
||||
@@ -65,7 +66,7 @@ int main(int, char **)
|
||||
builder.clear();
|
||||
structureArrayValue->toString(&builder);
|
||||
print("structureArrayValue");
|
||||
printf("PASSED\n");
|
||||
return(0);
|
||||
testPass("testStandardField");
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
||||
@@ -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/pvIntrospect.h>
|
||||
@@ -37,8 +37,9 @@ static void print(String name)
|
||||
if(debug) printf("\n%s\n%s\n",name.c_str(),builder.c_str());
|
||||
}
|
||||
|
||||
int main(int, char **)
|
||||
MAIN(testStandardPVField)
|
||||
{
|
||||
testPlan(1);
|
||||
PVStructurePtr pvStructure = standardPVField->scalar(pvDouble,
|
||||
"alarm,timeStamp,display,control,valueAlarm");
|
||||
PVDoublePtr pvValue = pvStructure->getDoubleField("value");
|
||||
@@ -80,7 +81,7 @@ int main(int, char **)
|
||||
builder.clear();
|
||||
pvStructure->toString(&builder);
|
||||
print("structureArrayTest");
|
||||
printf("PASSED\n");
|
||||
return(0);
|
||||
testPass("testStandardPVField");
|
||||
return testDone();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user