From 30362c59bc53ecaa152926aba829c607b82c6607 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 10 Jan 2016 12:33:47 +0100 Subject: [PATCH] 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. --- tests/core/proc/engine/testframe-test.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/core/proc/engine/testframe-test.cpp b/tests/core/proc/engine/testframe-test.cpp index 157d1a69f..ffd083ed8 100644 --- a/tests/core/proc/engine/testframe-test.cpp +++ b/tests/core/proc/engine/testframe-test.cpp @@ -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)); }