Browse Source

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

LIB-11
heck 11 months ago
parent
commit
d5c966ea6c
2 changed files with 24 additions and 2 deletions
  1. +5
    -2
      test/pitytest11/src/PityUnit.hh
  2. +19
    -0
      test/pitytest11/src/PityUnit.hxx

+ 5
- 2
test/pitytest11/src/PityUnit.hh View File

@ -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;
};


+ 19
- 0
test/pitytest11/src/PityUnit.hxx View File

@ -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