Browse Source

Tests: Utils - add pEpIdentList / Group / split createIdentity into createOwnIdent() / createCptIdent() / createRawIdent()

CPT == counterparty
LIB-11
heck 1 year ago
parent
commit
aa9139c1bc
2 changed files with 100 additions and 21 deletions
  1. +78
    -20
      test/framework/utils.cc
  2. +22
    -1
      test/framework/utils.hh

+ 78
- 20
test/framework/utils.cc View File

@ -43,6 +43,36 @@ namespace pEp {
return ret;
}
//IdentityList
pEpIdentList wrap(::identity_list *const ident)
{
assert(ident);
auto ret = pEpIdentList(ident, [](::identity_list *) {});
return ret;
}
pEpIdentList appropriate(::identity_list *const ident)
{
assert(ident);
auto ret = pEpIdentList(ident, ::free_identity_list);
return ret;
}
pEpIdentList dup(const ::identity_list *const ident)
{
assert(ident);
auto ret = pEpIdentList(::identity_list_dup(ident), ::free_identity_list);
return ret;
}
pEpIdentList kill(::identity_list *const ident)
{
assert(ident);
auto ret = pEpIdentList(::identity_list_dup(ident), ::free_identity_list);
::free_identity_list(ident);
return ret;
}
//Message
pEpMessage wrap(::message *const msg)
{
@ -74,28 +104,56 @@ namespace pEp {
}
// helpers
pEpIdent createIdentity(const std::string &address, bool myself)
pEpIdent createOwnIdent(const std::string &address)
{
std::string name;
std::string id;
::pEp_identity *partner = nullptr;
if (myself) {
partner = ::new_identity(
strdup(address.c_str()),
"",
PEP_OWN_USERID,
("myself " + address).c_str());
partner->me = true;
} else {
partner = ::new_identity(
strdup(address.c_str()),
"",
"23",
("partner " + address).c_str());
partner->me = false;
}
::pEp_identity *ident = nullptr;
ident = ::new_identity(
strdup(address.c_str()),
"",
PEP_OWN_USERID,
("myself " + address).c_str());
ident->me = true;
return appropriate(ident);
}
pEpIdent createCptIdent(const std::string &address)
{
std::string name;
::pEp_identity *ident = nullptr;
ident = ::new_identity(
strdup(address.c_str()),
"",
"23",
("partner " + address).c_str());
ident->me = false;
return appropriate(partner);
return appropriate(ident);
}
pEpIdent createRawIdent(const std::string &address)
{
std::string name;
::pEp_identity *ident = nullptr;
ident = ::new_identity(
strdup(address.c_str()),
"",
"",
"");
ident->me = false;
return appropriate(ident);
}
pEpIdentList createIdentityList(const std::vector<std::string> &addresses)
{
::identity_list *list;
list = ::new_identity_list(nullptr);
for (std::string addr : addresses) {
::identity_list_add(list, ::identity_dup(createCptIdent(addr).get()));
}
return appropriate(list);
}
pEpMessage createMessage(pEpIdent from, pEpIdent to, const std::string &longmsg)
@ -112,7 +170,7 @@ namespace pEp {
pEpMessage createMessage(pEpIdent from, const std::string &to_addr, const std::string &longmsg)
{
pEpIdent to_ident = createIdentity(to_addr, false);
pEpIdent to_ident = createCptIdent(to_addr);
return createMessage(from, to_ident, longmsg);
}


+ 22
- 1
test/framework/utils.hh View File

@ -12,6 +12,7 @@
#include <unistd.h>
#include <tuple>
#include <pEp/pEpEngine.h>
#include <pEp/identity_list.h>
#include <pEp/message.h>
#include <pEp/message_api.h>
@ -78,8 +79,11 @@ namespace pEp {
namespace Test {
namespace Utils {
using pEpIdent = std::shared_ptr<::pEp_identity>;
using pEpIdentList = std::shared_ptr<::identity_list>;
using pEpMessage = std::shared_ptr<::message>;
// [ DecryptedMessage, Rating, KeyList, Flags, WasEncrypted ]
using DecryptResult = std::tuple<pEpMessage, ::PEP_rating, ::stringlist_t *, unsigned int, bool>;
// [ EncryptedMessage, MimeText, couldEncrypt ]
using EncryptResult = std::tuple<pEpMessage, std::string, bool>;
// Datatypes
@ -89,17 +93,34 @@ namespace pEp {
pEpIdent dup(const ::pEp_identity *const ident);
pEpIdent kill(::pEp_identity *const ident);
//IdentityList
pEpIdentList wrap(::identity_list *const ident);
pEpIdentList appropriate(::identity_list *const ident);
pEpIdentList dup(const ::identity_list *const ident);
pEpIdentList kill(::identity_list *const ident);
//Message
pEpMessage wrap(::message *const msg);
pEpMessage appropriate(::message *const msg);
pEpMessage dup(const ::message *const msg);
pEpMessage kill(::message *const msg);
// Group
struct Group {
std::string name;
std::string moderator;
std::vector<std::string> members;
};
// helpers
pEpIdent createIdentity(const std::string &address, bool myself);
pEpIdent createOwnIdent(const std::string &address);
pEpIdent createCptIdent(const std::string &address);
pEpIdent createRawIdent(const std::string &address);
pEpIdentList createIdentityList(const std::vector<std::string> &addresses);
pEpMessage createMessage(pEpIdent from, pEpIdent to, const std::string &longmsg);
pEpMessage createMessage(pEpIdent from, const std::string &to_addr, const std::string &longmsg);
std::string mimeEncode(const pEpMessage msg);
pEpMessage mimeDecode(const std::string &mime_text);


Loading…
Cancel
Save