Test: PityTest - PityUnit add setContext() twice, pointer takes reference, Value copies and own the thing....

LIB-11
heck 2 years ago
parent 8fa9e24d1e
commit d5c966ea6c

@ -47,10 +47,12 @@ namespace pEp {
// copy-assign
PityUnit<TestContext>& operator=(const PityUnit<TestContext>& rhs);
PityUnit<TestContext>& getSelf() override;
// clone
PityUnit<TestContext>* 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<TestContext>& rhs);
// Fields
TestContext* _ctx; // nullptr if inherited
// nullptr if inherited
TestContext* _ctx;
std::shared_ptr<TestContext> _owned_ctx; // if you copy
TestFunction _test_func;
};

@ -60,6 +60,12 @@ namespace pEp {
return *this;
}
template<class TestContext>
PityUnit<TestContext> &PityUnit<TestContext>::getSelf()
{
return *this;
}
template<class TestContext>
PityUnit<TestContext> *PityUnit<TestContext>::clone()
{
@ -110,6 +116,19 @@ namespace pEp {
_ctx = nullptr;
}
}
template<class TestContext>
void PityUnit<TestContext>::setContext(TestContext *ctx)
{
_ctx = ctx;
}
template<class TestContext>
void PityUnit<TestContext>::setContext(TestContext ctx)
{
_owned_ctx = std::shared_ptr<TestContext>(new TestContext(ctx));
_ctx = _owned_ctx.get();
}
} // namespace PityTest11
} // namespace pEp

Loading…
Cancel
Save