2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/alloc/easy.hpp>
|
|
|
|
#include <cruft/util/alloc/linear.hpp>
|
|
|
|
#include <cruft/util/buffer/simple.hpp>
|
|
|
|
#include <cruft/util/tap.hpp>
|
2018-12-19 17:16:57 +11:00
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
struct setter {
|
|
|
|
setter (const setter&) = delete;
|
|
|
|
|
|
|
|
setter (bool &_target):
|
|
|
|
target (_target)
|
|
|
|
{ target = false; }
|
|
|
|
|
|
|
|
~setter ()
|
|
|
|
{ target = true; }
|
|
|
|
|
|
|
|
bool ⌖
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
static constexpr std::size_t elements = 4096;
|
2018-12-19 20:22:18 +11:00
|
|
|
cruft::buffer::simple buf (elements);
|
2018-12-19 17:16:57 +11:00
|
|
|
|
|
|
|
cruft::alloc::easy::owned <
|
2018-12-19 17:55:24 +11:00
|
|
|
cruft::alloc::linear,
|
2018-12-19 20:22:18 +11:00
|
|
|
cruft::buffer::simple
|
2018-12-19 17:16:57 +11:00
|
|
|
> alloc (
|
|
|
|
std::move (buf)
|
|
|
|
);
|
|
|
|
|
|
|
|
cruft::TAP::logger tap;
|
|
|
|
|
|
|
|
bool flag = true;
|
|
|
|
|
|
|
|
// double check our testing object is working, because I'm tired and stupid
|
|
|
|
{
|
|
|
|
setter val (flag);
|
|
|
|
CHECK (!flag);
|
|
|
|
}
|
|
|
|
CHECK (flag);
|
|
|
|
|
|
|
|
// ensure manual acquire and release calls constructors and destructors
|
|
|
|
{
|
|
|
|
auto obj = alloc.acquire<setter> (flag);
|
|
|
|
tap.expect_eq (flag, false, "backed::acquire calls constructor");
|
|
|
|
|
|
|
|
alloc.release (obj);
|
|
|
|
tap.expect_eq (flag, true, "backed::release calls destructor");
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure unique_ptr like objects call constructors and destructors
|
|
|
|
{
|
|
|
|
auto obj = alloc.unique<setter> (flag);
|
|
|
|
tap.expect_eq (flag, false, "backed::unique acquire calls constructor");
|
|
|
|
}
|
|
|
|
|
|
|
|
tap.expect_eq (flag, true, "backed::unique release calls destructor");
|
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|