36 using lumiera::error::LUMIERA_ERROR_ASSERTION;
47 virtual long apiFunc() =0;
49 virtual long& localSum() =0;
54 return unConst(
this)->localSum()
55 == unConst(o).localSum();
60 const uint MAX_RAND = 1000;
61 const uint MAX_ELM = 111;
62 const uint MAX_SIZ =
sizeof(
long[MAX_ELM]);
76 template<u
int ii,
class BASE=Interface>
83 mark (-1 * localSum());
84 CHECK (0 == localSum());
99 _checkSum += localSum();
103 operator= (
Imp const& o)
105 _checkSum -= localSum();
107 _checkSum += localSum();
115 long rr = ii * (1 +
rani(MAX_RAND));
124 return localData_[ii-1];
128 mark (
long markerValue)
130 localSum() += markerValue;
131 _checkSum += markerValue;
135 copyData (
Imp const& o)
137 for (uint i=0; i<ii; ++i)
138 localData_[i] = o.localData_[i];
152 using TestList = std::vector<PolyVal> ;
179 TestList objs = createOpaqueValues ();
180 for_each (objs, operate);
182 CHECK (0 == _checkSum);
184 verifyOverrunProtection();
185 verifyCopySupportDetectionMetafunctions();
190 createOpaqueValues ()
193 list.push_back (PolyVal::build<Imp<1>> () );
194 list.push_back (PolyVal::build<Imp<11>> () );
195 list.push_back (PolyVal::build<Imp<111>>() );
196 list.push_back (PolyVal::build<Imp<23>> () );
197 list.push_back (PolyVal::build<Imp<5>> () );
206 CHECK (elm == myLocalVal);
208 long prevSum = _callSum;
209 long randVal = myLocalVal->apiFunc();
210 CHECK (prevSum + randVal == _callSum);
211 CHECK (elm != myLocalVal);
214 CHECK (elm == myLocalVal);
215 CHECK (!isSameObject (elm, myLocalVal));
224 typedef Imp<MAX_ELM> MaximumSizedImp;
227 verifyCreation_and_Copy<PolyVal, MaximumSizedImp>();
231 using CopySupportingImp = Imp<MAX_ELM,CopySupportAPI>;
233 CHECK (
sizeof(OptimalPolyVal) <
sizeof(
PolyVal));
235 verifyCreation_and_Copy<OptimalPolyVal, CopySupportingImp>();
239 template<
class PV,
class IMP>
241 verifyCreation_and_Copy()
245 using Api =
typename PV::Interface ;
247 long prevSum = _checkSum;
248 uint prevCnt = _created;
250 Holder val = Holder::template build<ImpType>();
251 CHECK (prevSum+111 == _checkSum);
252 CHECK (prevCnt+1 <= _created);
253 CHECK (prevCnt+2 >= _created);
254 CHECK (
sizeof(Holder) >=
sizeof(ImpType));
256 CHECK (isSameObject(api,val));
266 CHECK (prevCnt+1 == _created);
271 verifyOverrunProtection()
273 typedef Imp<MAX_ELM+1> OversizedImp;
274 CHECK (MAX_SIZ <
sizeof(OversizedImp));
276 VERIFY_ERROR (ASSERTION, PolyVal::build<OversizedImp>() ); const size_t _ALIGN_
maximum additional storage maybe wasted due to alignment of the contained object within the embedded ...
#define INSTANCEOF(CLASS, EXPR)
shortcut for subclass test, intended for assertions only.
A variation for limited copy support.
helper to detect presence of a function to support clone operations
int rani(uint bound=_iBOUND())
bool operator==(PtrDerefIter< I1 > const &il, PtrDerefIter< I2 > const &ir)
Supporting equality comparisons...
A mechanism to allow for opaque polymorphic value objects.
trait template to deal with different ways to support copy operations.
Implementation namespace for support and library code.
Template to generate concrete implementation classes.
Simplistic test class runner.
Template to build polymorphic value objects.
helper to detect if the API supports only copy construction, but no assignment
void for_each(CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
Accept binding for arbitrary function arguments.
Interface for active support of copy operations by the embedded client objects.
A collection of frequently used helper functions to support unit testing.
void verifyCopySupportDetectionMetafunctions()
Perform operations "for each element" of a collection.
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee's memory identities. ...