diff --git a/src/types.cc b/src/types.cc index 6b340fa..066b5ac 100644 --- a/src/types.cc +++ b/src/types.cc @@ -19,10 +19,11 @@ namespace pEp ) {} +//////////////// template<> template<> - message* Wrapper<::message*>::_new(PEP_msg_direction dir, char* s) + message* Wrapper<::message*>::_new(PEP_msg_direction dir, const char* s) { message* m = new_message(dir); if(!m) @@ -32,6 +33,14 @@ namespace pEp return m; } + template<> + void Wrapper<::message*>::_free(::message* m) + { + free_message(m); + } + +//////////////// + template<> template<> ::stringpair_t* Wrapper<::stringpair_t*>::_new(const char* key, const char* value) @@ -51,9 +60,13 @@ namespace pEp return Wrapper<::stringpair_t*>::_new(key.c_str(), value.c_str()); } + template<> + void Wrapper<::stringpair_t*>::_free(::stringpair_t* sp) + { + free_stringpair(sp); + } - Message m(PEP_dir_incoming, "Foo"); - StringPair sp(std::string("foo"), std::string("bar")); +//////////////// template class Wrapper<::pEp_identity>; template class Wrapper<::stringpair_t>; diff --git a/src/types.hh b/src/types.hh index 809884e..18f97ec 100644 --- a/src/types.hh +++ b/src/types.hh @@ -19,10 +19,10 @@ namespace pEp EngineError(PEP_STATUS status, const char* message = nullptr); }; - using Identity = Wrapper<::pEp_identity>; - using StringPair = Wrapper<::stringpair_t>; + using Identity = Wrapper<::pEp_identity*>; + using StringPair = Wrapper<::stringpair_t*>; - using Message = Wrapper<::message>; + using Message = Wrapper<::message*>; } // end of namespace pEp diff --git a/src/wrapper.hh b/src/wrapper.hh index 77487f2..2733539 100644 --- a/src/wrapper.hh +++ b/src/wrapper.hh @@ -58,14 +58,14 @@ public: Wrapper&& operator=(Wrapper&& victim) { - _free(); + _free(value); value = victim.value; victim.value = nullptr; } ~Wrapper() { - _free(); + _free(value); } @@ -74,7 +74,7 @@ private: template T* _new(Args...); - void _free(); + void _free(T*); T* value; }; diff --git a/test/unittest_stringpair.cc b/test/unittest_stringpair.cc new file mode 100644 index 0000000..c44e821 --- /dev/null +++ b/test/unittest_stringpair.cc @@ -0,0 +1,10 @@ +#include + +#include "../src/types.hh" + + +TEST( StringPair, T1 ) +{ + pEp::StringPair s1{"key", "value"}; +// pEp::StringPair s2{ std::string{"key2"}, std::string{"value"} }; +}