Browse Source

Tests: add util functions

add vector_to_string<T>()
add print_exception() - to print nested exceptions
LIB-12
heck 4 years ago
parent
commit
591b5c0fc2
  1. 12
      test/framework/utils.cc
  2. 11
      test/framework/utils.hh
  3. 24
      test/framework/utils.hxx

12
test/framework/utils.cc

@ -160,6 +160,18 @@ namespace pEp {
return builder.str();
}
void print_exception(const exception& e, int level)
{
cerr << string(level, ' ') << "exception: " << e.what() << endl;
try {
rethrow_if_nested(e);
} catch (const exception& e) {
print_exception(e, level + 1);
} catch (...) {
}
}
} // namespace Utils
} // namespace Test
} // namespace pEp

11
test/framework/utils.hh

@ -8,6 +8,7 @@
#include <pEp/message.h>
#include <pEp/identity_list.h>
#include <pEp/group.h>
#include <exception>
namespace pEp {
namespace Test {
@ -21,7 +22,15 @@ namespace pEp {
std::string member_to_string(::pEp_member *member, bool full = true, int indent = 0);
std::string memberlist_to_string(::member_list *mbl, bool full = true, int indent = 0);
std::string group_to_string(::pEp_group *group, bool full = true, int indent = 0);
template<typename T>
std::string vector_to_string(std::vector<T> v);
void print_exception(const std::exception& e, int level = 0);
}
} // namespace Test
} // namespace pEp
#endif
#include "utils.hxx"
#endif // LIBPEPADAPTER_UTILS_HH

24
test/framework/utils.hxx

@ -0,0 +1,24 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#ifndef LIBPEPADAPTER_UTILS_HXX
#define LIBPEPADAPTER_UTILS_HXX
#include <sstream>
namespace pEp {
namespace Test {
namespace Utils {
template<typename T>
std::string vector_to_string(std::vector<T> v)
{
std::stringstream ss;
for (const T& elem : v) {
ss << elem << std::endl;
}
return ss.str();
}
}
} // namespace Test
} // namespace pEp
#endif // LIBPEPADAPTER_UTILS_HXX
Loading…
Cancel
Save