45 using lumiera::error::LUMIERA_ERROR_ASSERTION;
56 virtual long apiFunc() =0;
58 virtual long& localSum() =0;
63 return unConst(
this)->localSum()
64 == unConst(o).localSum();
69 const uint MAX_RAND = 1000;
70 const uint MAX_ELM = 111;
71 const uint MAX_SIZ =
sizeof(
long[MAX_ELM]);
85 template<u
int ii,
class BASE=Interface>
92 mark (-1 * localSum());
93 CHECK (0 == localSum());
108 _checkSum += localSum();
112 operator= (
Imp const& o)
114 _checkSum -= localSum();
116 _checkSum += localSum();
124 long rr = ii * (1 + rand() % MAX_RAND);
133 return localData_[ii-1];
137 mark (
long markerValue)
139 localSum() += markerValue;
140 _checkSum += markerValue;
144 copyData (
Imp const& o)
146 for (uint i=0; i<ii; ++i)
147 localData_[i] = o.localData_[i];
161 using TestList = std::vector<PolyVal> ;
187 TestList objs = createOpaqueValues ();
188 for_each (objs, operate);
190 CHECK (0 == _checkSum);
192 verifyOverrunProtection();
193 verifyCopySupportDetectionMetafunctions();
198 createOpaqueValues ()
201 list.push_back (PolyVal::build<Imp<1>> () );
202 list.push_back (PolyVal::build<Imp<11>> () );
203 list.push_back (PolyVal::build<Imp<111>>() );
204 list.push_back (PolyVal::build<Imp<23>> () );
205 list.push_back (PolyVal::build<Imp<5>> () );
214 CHECK (elm == myLocalVal);
216 long prevSum = _callSum;
217 long randVal = myLocalVal->apiFunc();
218 CHECK (prevSum + randVal == _callSum);
219 CHECK (elm != myLocalVal);
222 CHECK (elm == myLocalVal);
223 CHECK (!isSameObject (elm, myLocalVal));
232 typedef Imp<MAX_ELM> MaximumSizedImp;
235 verifyCreation_and_Copy<PolyVal, MaximumSizedImp>();
239 using CopySupportingImp = Imp<MAX_ELM,CopySupportAPI>;
241 CHECK (
sizeof(OptimalPolyVal) <
sizeof(
PolyVal));
243 verifyCreation_and_Copy<OptimalPolyVal, CopySupportingImp>();
247 template<
class PV,
class IMP>
249 verifyCreation_and_Copy()
253 using Api =
typename PV::Interface ;
255 long prevSum = _checkSum;
256 uint prevCnt = _created;
258 Holder val = Holder::template build<ImpType>();
259 CHECK (prevSum+111 == _checkSum);
260 CHECK (prevCnt+1 <= _created);
261 CHECK (prevCnt+2 >= _created);
262 CHECK (
sizeof(Holder) >=
sizeof(ImpType));
264 CHECK (isSameObject(api,val));
274 CHECK (prevCnt+1 == _created);
279 verifyOverrunProtection()
281 typedef Imp<MAX_ELM+1> OversizedImp;
282 CHECK (MAX_SIZ <
sizeof(OversizedImp));
284 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
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.
Simple 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, bypassing any custom comparison operators.