fix a long standing Heisenbug in ScopedCollection_test
...other than intended, the bomb did explode on random occasions, with an probability of about 4% (when rr >= 96). Btw, there was also the mistake to throw an heap allocated object by pointer. Damn Java habits.
This commit is contained in:
parent
b021a2e769
commit
5e16431b44
2 changed files with 11 additions and 3 deletions
|
|
@ -360,6 +360,7 @@ namespace lib {
|
|||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////TICKET #967 : the following can be written better now. Also should be named 'emplace'
|
||||
/** push a new element of default type
|
||||
* to the end of this container
|
||||
* @note EX_STRONG */
|
||||
|
|
@ -551,7 +552,7 @@ namespace lib {
|
|||
/** \par usage
|
||||
* Pass an instance of this builder functor as 2nd parameter
|
||||
* to ScopedCollections's ctor. (an anonymous instance is OK).
|
||||
* Using this variant of the compiler switches the collection to RAII-style:
|
||||
* Using this variant of the ctor switches the collection to RAII-style:
|
||||
* It will immediately try to create all the embedded objects, invoking this
|
||||
* builder functor for each "slot" to hold such an embedded object. Actually,
|
||||
* this "slot" is an ElementHolder instance, which provides functions for
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace test{
|
|||
, trigger_(trigger)
|
||||
{
|
||||
if (trigger == getVal())
|
||||
throw new error::Fatal ("Subversive Bomb", LUMIERA_ERROR_SUBVERSIVE);
|
||||
throw error::Fatal ("Subversive Bomb", LUMIERA_ERROR_SUBVERSIVE);
|
||||
}
|
||||
|
||||
SubDummy()
|
||||
|
|
@ -290,7 +290,7 @@ namespace test{
|
|||
CHECK (0 == Dummy::checksum());
|
||||
{
|
||||
int rr = rand() % 100;
|
||||
int trigger = 101;
|
||||
int trigger = 100 + 5 + 1; // prevents the bomb from exploding (since rr < 100)
|
||||
|
||||
CollD coll (6, Populator(rr, trigger));
|
||||
|
||||
|
|
@ -304,6 +304,13 @@ namespace test{
|
|||
CHECK (coll[3].acc(0) == 3 + rr + trigger);
|
||||
CHECK (coll[4].acc(0) == 4 + rr);
|
||||
CHECK (coll[5].acc(0) == 5 + rr + trigger);
|
||||
// what does this check prove?
|
||||
// - the container was indeed populated with DubDummy objects
|
||||
// since the overridden version of Dummy::acc() did run and
|
||||
// reveal the trigger value
|
||||
// - the population was indeed done with the anonymous Populator
|
||||
// instance fed to the ctor, since this object was "marked" with
|
||||
// the random value rr, and adds this mark to the built values.
|
||||
|
||||
coll.clear();
|
||||
CHECK (0 == Dummy::checksum());
|
||||
|
|
|
|||
Loading…
Reference in a new issue