From 450acba1bc48a1b445972cd77e2bf05139c3b209 Mon Sep 17 00:00:00 2001 From: roker Date: Mon, 14 Jun 2021 13:02:30 +0200 Subject: [PATCH] now the unittests compile. \o/ All declared functions & variables are defined. --- src/types.cc | 30 +++++++++++++++++++++++++++++- test/unittest_stringpair.cc | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/types.cc b/src/types.cc index 845aaab..c1d1c6f 100644 --- a/src/types.cc +++ b/src/types.cc @@ -52,7 +52,17 @@ namespace pEp } return sp; } - + + template<> + template<> + ::stringpair_t* Wrapper<::stringpair_t*>::_new(char* key, char* value) + { + return _new( + const_cast(key), + const_cast(value) + ); + } + template<> template<> ::stringpair_t* Wrapper<::stringpair_t*>::_new(const std::string& key, const std::string& value) @@ -117,6 +127,23 @@ namespace pEp { stringpair_list_add(value, sp.move_out()); } + + template<> + ListWrapper<::stringpair_list_t*, stringpair_t*>::ListWrapper(const std::initializer_list& il) + : StringPairList{} + { + ::stringpair_list_t* last = nullptr; + for(const StringPair& sp : il) + { + last = stringpair_list_add(last, stringpair_dup(sp.get())); + if(last==nullptr) + { + throw std::runtime_error("Cannot create StringPairList from {}: Out Of Memory."); + } + if(value==nullptr) + value = last; // save the head of linked list. + } + } //////////////// @@ -124,5 +151,6 @@ namespace pEp template class Wrapper<::stringpair_t>; template class Wrapper<::message>; + template class ListWrapper<::stringpair_list_t*, ::stringpair_t*>; } // end of namespace pEp diff --git a/test/unittest_stringpair.cc b/test/unittest_stringpair.cc index 9a3005c..6a4e24b 100644 --- a/test/unittest_stringpair.cc +++ b/test/unittest_stringpair.cc @@ -44,7 +44,7 @@ TEST( StringPair, Dynamic ) EXPECT_EQ(spl.size(), u); snprintf(key, 15, "k%u", u); snprintf(value, 15, "v%u", u*91); - spl.push_back( pEp::StringPair{key, value}.move_out() ); + spl.push_back( pEp::StringPair{key, value} ); } auto find_by_key = [key](const ::stringpair_t* sp){ return strcmp(sp->key, key)==0; };