From 4556745d773e0386d186bf992f85f1d87b89e435 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 19 Nov 2015 16:46:44 +1100 Subject: [PATCH] memory/deleter: add trivial test case --- Makefile.am | 1 + test/memory/deleter.cpp | 50 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 test/memory/deleter.cpp diff --git a/Makefile.am b/Makefile.am index 81f2fdd7..7205019a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -428,6 +428,7 @@ TEST_BIN = \ test/json_types \ test/memory/buffer/circular \ test/memory/buffer/paged \ + test/memory/deleter \ test/maths \ test/matrix \ test/md2 \ diff --git a/test/memory/deleter.cpp b/test/memory/deleter.cpp new file mode 100644 index 00000000..3e1bd2ac --- /dev/null +++ b/test/memory/deleter.cpp @@ -0,0 +1,50 @@ +#include "memory/deleter.hpp" +#include "tap.hpp" + +#include + + +struct setter { + setter (bool &_flag): + flag (_flag) + { ; } + + void release (unsigned *) + { flag = true; } + + bool &flag; +}; + + +int +main (void) +{ + bool flag = false; + + { + // setup a pretend resource. we're not going to delete it, it's just + // to satisfy some required parameters. importantly it can't be null + // otherwise release is skipped. + unsigned *foo = reinterpret_cast (0x01); + + // setup the owner who will set a flag when the release operation is + // called + setter bar (flag); + + // setup our non-default unique_ptr + std::unique_ptr< + unsigned, + util::memory::owner_deleter< + unsigned, + setter, + &setter::release + > + > qux (foo, bar); + } + + // the flag should have been implicitly set to true via the unique_ptr + // callback above + util::TAP::logger tap; + tap.expect (flag, "owner_deleter calls registered callback"); + return tap.status (); +}