From d5c966ea6c295d7be642d575ef6b6b3f068c5905 Mon Sep 17 00:00:00 2001 From: heck Date: Sat, 10 Jul 2021 13:37:16 +0200 Subject: [PATCH] Test: PityTest - PityUnit add setContext() twice, pointer takes reference, Value copies and own the thing.... --- test/pitytest11/src/PityUnit.hh | 7 +++++-- test/pitytest11/src/PityUnit.hxx | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/test/pitytest11/src/PityUnit.hh b/test/pitytest11/src/PityUnit.hh index b8da15c..2b91434 100644 --- a/test/pitytest11/src/PityUnit.hh +++ b/test/pitytest11/src/PityUnit.hh @@ -47,10 +47,12 @@ namespace pEp { // copy-assign PityUnit& operator=(const PityUnit& rhs); + PityUnit& getSelf() override; // clone PityUnit* clone() override; - // Read-Only + void setContext(TestContext* ctx); + void setContext(TestContext ctx); TestContext* getContext() const; protected: @@ -60,7 +62,8 @@ namespace pEp { void _copyContext(const PityUnit& rhs); // Fields - TestContext* _ctx; // nullptr if inherited + // nullptr if inherited + TestContext* _ctx; std::shared_ptr _owned_ctx; // if you copy TestFunction _test_func; }; diff --git a/test/pitytest11/src/PityUnit.hxx b/test/pitytest11/src/PityUnit.hxx index 19a3aaf..1ef51b2 100644 --- a/test/pitytest11/src/PityUnit.hxx +++ b/test/pitytest11/src/PityUnit.hxx @@ -60,6 +60,12 @@ namespace pEp { return *this; } + template + PityUnit &PityUnit::getSelf() + { + return *this; + } + template PityUnit *PityUnit::clone() { @@ -110,6 +116,19 @@ namespace pEp { _ctx = nullptr; } } + + template + void PityUnit::setContext(TestContext *ctx) + { + _ctx = ctx; + } + + template + void PityUnit::setContext(TestContext ctx) + { + _owned_ctx = std::shared_ptr(new TestContext(ctx)); + _ctx = _owned_ctx.get(); + } } // namespace PityTest11 } // namespace pEp