summaryrefslogtreecommitdiff
path: root/libadhocutil/unittests/testLazyPointer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libadhocutil/unittests/testLazyPointer.cpp')
-rw-r--r--libadhocutil/unittests/testLazyPointer.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/libadhocutil/unittests/testLazyPointer.cpp b/libadhocutil/unittests/testLazyPointer.cpp
index 52e5c79..31b92a5 100644
--- a/libadhocutil/unittests/testLazyPointer.cpp
+++ b/libadhocutil/unittests/testLazyPointer.cpp
@@ -17,6 +17,11 @@ class Test {
using TestLazyPointer = LazyPointer<Test>;
using RawLazyPointer = LazyPointer<int, int *>;
+/// LCOV_EXCL_START (diagnostics)
+BOOST_TEST_DONT_PRINT_LOG_VALUE(TestLazyPointer);
+BOOST_TEST_DONT_PRINT_LOG_VALUE(RawLazyPointer);
+/// LCOV_EXCL_STOP
+
static
TestLazyPointer::pointer_type
factory()
@@ -33,12 +38,11 @@ paramFactory(const std::string & str)
BOOST_AUTO_TEST_CASE ( islazy )
{
- TestLazyPointer p(std::bind(&factory));
+ TestLazyPointer p([]{ return factory(); });
BOOST_REQUIRE_EQUAL(false, p.hasValue());
Test * t = p.get();
BOOST_REQUIRE(t);
- bool pbool = p;
- BOOST_REQUIRE(pbool);
+ BOOST_REQUIRE(p);
BOOST_REQUIRE_EQUAL(true, p.hasValue());
BOOST_REQUIRE_EQUAL(p, t);
BOOST_REQUIRE_EQUAL(3, t->val);
@@ -48,7 +52,7 @@ BOOST_AUTO_TEST_CASE ( islazy )
BOOST_AUTO_TEST_CASE ( preinit )
{
Test * t = new Test(4);
- TestLazyPointer p(t);
+ TestLazyPointer p(TestLazyPointer::pointer_type{ t });
BOOST_REQUIRE_EQUAL(true, p.hasValue());
BOOST_REQUIRE_EQUAL(p, t);
BOOST_REQUIRE_EQUAL(4, p->val);
@@ -57,22 +61,22 @@ BOOST_AUTO_TEST_CASE ( preinit )
BOOST_AUTO_TEST_CASE ( reset )
{
Test * t = new Test(4);
- TestLazyPointer p(t);
+ TestLazyPointer p(TestLazyPointer::pointer_type{ t });
BOOST_REQUIRE_EQUAL(true, p.hasValue());
BOOST_REQUIRE_EQUAL(4, p->val);
p = nullptr;
BOOST_REQUIRE_EQUAL(true, p.hasValue());
BOOST_REQUIRE_EQUAL(true, !p);
- p = std::bind(&factory);
+ p = []{ return factory(); };
BOOST_REQUIRE_EQUAL(false, p.hasValue());
- p.get();
+ BOOST_REQUIRE(p.get());
BOOST_REQUIRE_EQUAL(true, p.hasValue());
BOOST_REQUIRE_EQUAL(3, p->val);
}
BOOST_AUTO_TEST_CASE ( nondefault )
{
- TestLazyPointer p(std::bind(&paramFactory, "some string"));
+ TestLazyPointer p([]{ return paramFactory("some string"); });
BOOST_REQUIRE_EQUAL(false, p.hasValue());
BOOST_REQUIRE_EQUAL(11, (*p).val);
BOOST_REQUIRE_EQUAL(true, p.hasValue());
@@ -93,9 +97,9 @@ BOOST_AUTO_TEST_CASE( rawPointerNonNull )
BOOST_REQUIRE(value);
BOOST_REQUIRE(value.get());
BOOST_REQUIRE_EQUAL(*value, 3);
- int * x = value;
+ int * x = (int *)value;
BOOST_REQUIRE_EQUAL(*x, 3);
- delete value;
+ delete x;
}
int *
@@ -106,10 +110,10 @@ rawFactory(const std::string & s)
BOOST_AUTO_TEST_CASE( rawPointerFactory )
{
- RawLazyPointer value(std::bind(&rawFactory, std::string("four")));
+ RawLazyPointer value([]{ return rawFactory(std::string("four")); });
BOOST_REQUIRE(!value.hasValue());
BOOST_REQUIRE_EQUAL(*value, 4);
BOOST_REQUIRE(value.hasValue());
- delete value;
+ delete (int *)value;
}