Browse Source

add unittest_stringpair; fix linker errors.

master
roker 4 years ago
parent
commit
d52ed09280
  1. 19
      src/types.cc
  2. 6
      src/types.hh
  3. 6
      src/wrapper.hh
  4. 10
      test/unittest_stringpair.cc

19
src/types.cc

@ -19,10 +19,11 @@ namespace pEp
)
{}
////////////////
template<>
template<>
message* Wrapper<::message*>::_new<PEP_msg_direction, char*>(PEP_msg_direction dir, char* s)
message* Wrapper<::message*>::_new<PEP_msg_direction, const char*>(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>;

6
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

6
src/wrapper.hh

@ -58,14 +58,14 @@ public:
Wrapper<T*>&& operator=(Wrapper<T*>&& victim)
{
_free();
_free(value);
value = victim.value;
victim.value = nullptr;
}
~Wrapper()
{
_free();
_free(value);
}
@ -74,7 +74,7 @@ private:
template<class... Args>
T* _new(Args...);
void _free();
void _free(T*);
T* value;
};

10
test/unittest_stringpair.cc

@ -0,0 +1,10 @@
#include <gtest/gtest.h>
#include "../src/types.hh"
TEST( StringPair, T1 )
{
pEp::StringPair s1{"key", "value"};
// pEp::StringPair s2{ std::string{"key2"}, std::string{"value"} };
}
Loading…
Cancel
Save