improve a shaky test definition

we deleted an object on the heap,
and afterwards re-accessed the memory through the
dangling pointer to verify the deletion actually happened.

This works most of the time, unless the memory manager decides
to map that page differently -- in which case we just hit
random memory contents.

A better idea is thus to place this TestFrame object
into a statically allocated buffer and invoke the dtor
explicitly. This allows us to conduct the test reliably.
This commit is contained in:
Fischlurch 2016-01-10 12:33:47 +01:00
parent ecd1375e92
commit 30362c59bc

View file

@ -125,15 +125,17 @@ namespace test {
CHECK (!TestFrame::isDead (this));
CHECK (!TestFrame::isAlive (this));
TestFrame* onHeap = new TestFrame(23);
CHECK ( TestFrame::isAlive (onHeap));
CHECK (!onHeap->isDead());
CHECK (onHeap->isAlive());
CHECK (onHeap->isSane());
static char buffer[sizeof(TestFrame)];
TestFrame* frame = new(&buffer) TestFrame(23);
delete onHeap;
CHECK ( TestFrame::isDead (onHeap));
CHECK (!TestFrame::isAlive (onHeap));
CHECK ( TestFrame::isAlive (frame));
CHECK (!frame->isDead());
CHECK (frame->isAlive());
CHECK (frame->isSane());
frame->~TestFrame();
CHECK ( TestFrame::isDead (frame));
CHECK (!TestFrame::isAlive (frame));
}