2015-11-24 16:52:47 +11:00
|
|
|
#include "tap.hpp"
|
2018-01-09 16:28:25 +11:00
|
|
|
|
2015-11-24 16:52:47 +11:00
|
|
|
#include "alloc/arena.hpp"
|
2017-08-29 16:53:11 +10:00
|
|
|
#include "alloc/raw/linear.hpp"
|
2018-01-09 16:28:25 +11:00
|
|
|
#include "debug.hpp"
|
2015-11-24 16:52:47 +11:00
|
|
|
|
|
|
|
|
2017-08-29 16:53:11 +10:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2018-03-02 12:18:20 +11:00
|
|
|
static std::byte g_backing[1024*1024];
|
2015-11-24 16:52:47 +11:00
|
|
|
|
|
|
|
|
2017-08-29 16:53:11 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
2015-11-24 16:52:47 +11:00
|
|
|
struct setter {
|
2016-07-28 13:38:34 +10:00
|
|
|
setter (const setter&) = delete;
|
|
|
|
|
2015-11-24 16:52:47 +11:00
|
|
|
setter (bool &_target):
|
|
|
|
target (_target)
|
|
|
|
{ target = false; }
|
|
|
|
|
|
|
|
~setter ()
|
|
|
|
{ target = true; }
|
|
|
|
|
|
|
|
bool ⌖
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-08-29 16:53:11 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
2015-11-24 16:52:47 +11:00
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::alloc::raw::linear alloc (cruft::make_view (g_backing));
|
|
|
|
cruft::alloc::arena<cruft::alloc::raw::linear> arena (alloc);
|
2015-11-24 16:52:47 +11:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2015-11-24 16:52:47 +11:00
|
|
|
|
|
|
|
bool flag = true;
|
|
|
|
|
|
|
|
// double check our testing object is working, because I'm tired and stupid
|
|
|
|
{
|
2016-07-28 13:38:34 +10:00
|
|
|
setter val (flag);
|
2015-11-24 16:52:47 +11:00
|
|
|
CHECK (!flag);
|
|
|
|
}
|
|
|
|
CHECK (flag);
|
|
|
|
|
|
|
|
// ensure manual acquire and release calls constructors and destructors
|
|
|
|
{
|
|
|
|
auto obj = arena.acquire<setter> (flag);
|
|
|
|
tap.expect_eq (flag, false, "arena manual acquire calls constructor");
|
|
|
|
|
|
|
|
arena.release (obj);
|
|
|
|
tap.expect_eq (flag, true, "arena manual release calls destructor");
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure unique_ptr like objects call constructors and destructors
|
|
|
|
{
|
|
|
|
auto obj = arena.unique<setter> (flag);
|
|
|
|
tap.expect_eq (flag, false, "arena unique acquire calls constructor");
|
|
|
|
}
|
|
|
|
|
|
|
|
tap.expect_eq (flag, true, "arena unique release calls destructor");
|
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|