4 #include "epicsUnitTest.h" 5 #include "epicsString.h" 18 std::vector<double> darr;
21 explicit mine(
const std::string& n) :
ObjectInst<mine>(n), ival(0), dval(0.0), count(0)
25 virtual void lock()
const{};
26 virtual void unlock()
const{};
28 int getI()
const{
return ival;}
29 void setI(
int i){ival=i;}
31 double val()
const{
return dval;}
32 void setVal(
double v){dval=v;}
34 epicsUInt32 getdarr(
double* v, epicsUInt32 l)
const 36 if (!v)
return (epicsUInt32)darr.size();
37 l = (epicsUInt32)std::min((
size_t)l, darr.size());
38 std::copy(darr.begin(), darr.begin()+l, v);
41 void setdarr(
const double* v, epicsUInt32 l)
44 std::copy(v, v+l, darr.begin());
47 void incr() { count++; }
54 explicit other(
const std::string& n) : base_t(n) {}
57 int getX()
const {
return 42;}
65 return new other(name);
71 testDiag(
"In testMine()");
76 mrf::auto_ptr<property<int> > I=m.getProperty<
int>(
"I");
77 testOk1(I.get()!=NULL);
87 mrf::auto_ptr<property<double> > V=o->
getProperty<
double>(
"val");
88 testOk1(V.get()!=NULL);
91 testOk1(V->get()==0.0);
96 mrf::auto_ptr<property<int> > I2=o->
getProperty<
int>(
"I");
97 testOk1(I2.get()!=NULL);
101 testOk1(I2->get()==42);
104 testOk1(I2.get()!=NULL);
105 testOk1((*I)!=(*I2));
108 testOk1(I2->get()==42);
110 mrf::auto_ptr<property<double[1]> > A=o->
getProperty<
double[1]>(
"darr");
111 testOk1(A.get()!=NULL);
113 const double tst[] = {1.0, 2.0, 3.0};
118 testOk1(m.darr.size()==3);
119 testOk1(A->get(tst2,3)==3);
122 testOk1(std::equal(tst,tst+3,tst2));
125 testOk1(V.get()==NULL);
129 testFail(
"Duplicate name not prevented");
130 }
catch(std::runtime_error& e) {
131 testPass(
"Duplicate name prevented: %s",e.what());
140 mrf::auto_ptr<property<void> > incr(o->
getProperty<
void>(
"incr"));
141 testOk1(incr.get()!=NULL);
151 testDiag(
"In testOther()");
154 mrf::auto_ptr<property<double> > V=m.getProperty<
double>(
"val");
155 testOk1(V.get()!=NULL);
157 mrf::auto_ptr<property<int> > I=m.getProperty<
int>(
"I");
158 testOk1(I.get()!=NULL);
160 mrf::auto_ptr<property<double[1]> > A=m.getProperty<
double[1]>(
"darr");
161 testOk1(A.get()!=NULL);
163 mrf::auto_ptr<property<int> > X=m.getProperty<
int>(
"X");
164 testOk1(X.get()!=NULL);
167 testOk1(X->get()==42);
174 testDiag(
"In testOther2()");
178 mrf::auto_ptr<property<double> > V=o->
getProperty<
double>(
"val");
179 testOk1(V.get()!=NULL);
181 mrf::auto_ptr<property<int> > I=o->
getProperty<
int>(
"I");
182 testOk1(I.get()!=NULL);
184 mrf::auto_ptr<property<double[1]> > A=o->
getProperty<
double[1]>(
"darr");
185 testOk1(A.get()!=NULL);
187 mrf::auto_ptr<property<int> > X=o->
getProperty<
int>(
"X");
188 testOk1(X.get()!=NULL);
193 testDiag(
"In testFactory()");
194 other m(
"HelloWorld");
202 testOk1(built!=NULL);
std::map< std::string, std::string > create_args_t
static Object * getCreateObject(const std::string &name, const std::string &klass, const create_args_t &args=create_args_t())
OBJECT_FACTORY(other::buildOne)
OBJECT_PROP1("incr", &mine::incr)
#define OBJECT_BEGIN2(klass, Base)
OBJECT_PROP2("I", &mine::getI, &mine::setI)
static Object * getObject(const std::string &name)
#define OBJECT_BEGIN(klass)
User implementation hook.
#define OBJECT_END(klass)
mrf::auto_ptr< property< P > > getProperty(const char *pname)