
18 changed files with 881 additions and 98 deletions
@ -0,0 +1,96 @@ |
|||
// This file is under GNU General Public License 3.0
|
|||
// see LICENSE.txt
|
|||
#include <pEp/group.h> |
|||
|
|||
#include "adapter_group.h" |
|||
#include "pEpLog.hh" |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
/*************************************************************************************************
|
|||
* Group management functions |
|||
*************************************************************************************************/ |
|||
|
|||
DYNAMIC_API PEP_STATUS adapter_group_create( |
|||
PEP_SESSION session, |
|||
pEp_identity *group_identity, |
|||
pEp_identity *manager, |
|||
identity_list *memberlist, |
|||
pEp_group **group) |
|||
{ |
|||
pEpLog("called"); |
|||
return ::group_create(session, group_identity, manager, memberlist, group); |
|||
} |
|||
|
|||
DYNAMIC_API PEP_STATUS |
|||
adapter_group_join(PEP_SESSION session, pEp_identity *group_identity, pEp_identity *as_member) |
|||
{ |
|||
pEpLog("called"); |
|||
return ::group_join(session, group_identity, as_member); |
|||
} |
|||
|
|||
DYNAMIC_API PEP_STATUS |
|||
adapter_group_dissolve(PEP_SESSION session, pEp_identity *group_identity, pEp_identity *manager) |
|||
{ |
|||
pEpLog("called"); |
|||
return ::group_dissolve(session, group_identity, manager); |
|||
} |
|||
|
|||
DYNAMIC_API PEP_STATUS adapter_group_invite_member( |
|||
PEP_SESSION session, |
|||
pEp_identity *group_identity, |
|||
pEp_identity *group_member) |
|||
{ |
|||
pEpLog("called"); |
|||
return ::group_invite_member(session, group_identity, group_member); |
|||
} |
|||
|
|||
PEP_STATUS adapter_group_remove_member( |
|||
PEP_SESSION session, |
|||
pEp_identity *group_identity, |
|||
pEp_identity *group_member) |
|||
{ |
|||
pEpLog("called"); |
|||
return ::group_remove_member(session, group_identity, group_member); |
|||
} |
|||
|
|||
DYNAMIC_API PEP_STATUS adapter_group_rating( |
|||
PEP_SESSION session, |
|||
pEp_identity *group_identity, |
|||
pEp_identity *manager, |
|||
PEP_rating *rating) |
|||
{ |
|||
pEpLog("called"); |
|||
return ::group_rating(session, group_identity, manager, rating); |
|||
} |
|||
|
|||
/*************************************************************************************************
|
|||
* Group query functions |
|||
*************************************************************************************************/ |
|||
|
|||
|
|||
//DYNAMIC_API PEP_STATUS group_query_groups(PEP_SESSION session, identity_list **groups)
|
|||
//{
|
|||
// pEpLog("called");
|
|||
// return PEP_STATUS_OK;
|
|||
//}
|
|||
//
|
|||
//DYNAMIC_API PEP_STATUS
|
|||
//group_query_manager(PEP_SESSION session, const pEp_identity *const group, pEp_identity **manager)
|
|||
//{
|
|||
// pEpLog("called");
|
|||
// return PEP_STATUS_OK;
|
|||
//}
|
|||
//
|
|||
//DYNAMIC_API PEP_STATUS
|
|||
//group_query_members(PEP_SESSION session, const pEp_identity *const group, identity_list **members)
|
|||
//{
|
|||
// pEpLog("called");
|
|||
// return PEP_STATUS_OK;
|
|||
//}
|
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
@ -0,0 +1,276 @@ |
|||
// This file is under GNU General Public License 3.0
|
|||
// see LICENSE.txt
|
|||
|
|||
#ifndef LIBPEPADAPTER_GROUP_HH |
|||
#define LIBPEPADAPTER_GROUP_HH |
|||
|
|||
#include <pEp/message_api.h> |
|||
#include <pEp/group.h> |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
|
|||
/*************************************************************************************************
|
|||
* Group management functions |
|||
*************************************************************************************************/ |
|||
|
|||
/**
|
|||
* <!-- adapter_group_create() --> |
|||
* |
|||
* @brief Create a group in the database with the input group_identity and manager and invite new members to the group |
|||
* if this is an own group (for the external API, this is always the case). |
|||
* |
|||
* This function sets up the actual database structures for a group and invites new members to the group. |
|||
* |
|||
* For the external API, it is used when creating an own group. The group is represented by the |
|||
* incoming group_identity, which contains the user_id and address for the group. |
|||
* If no key is present for the former, it will be generated - if there is already |
|||
* a default key for the group_identity in the database, that will be used instead. |
|||
* The manager |
|||
* |
|||
* @param[in] session associated session object |
|||
* @param[in,out] group_identity the pEp_identity object representing the group. Must contain at least |
|||
* a user_id and address |
|||
* @param[in,out] manager the pEp_identity object representing the group's manager. Must contain |
|||
* a user_id and address, and there must be a default key for the manager |
|||
* present in the database |
|||
* @param[in,out] member_ident_list list of group member identities |
|||
* @param[in,out] group Optional reference for pointer to group object |
|||
* representing the created group. |
|||
* (When input is NULL, no object is created) |
|||
* |
|||
* @retval PEP_STATUS_OK on success |
|||
* error on failure |
|||
* |
|||
* @ownership All input values stay with the caller |
|||
* |
|||
* @warning starts a DB transaction - do not call from within a function which |
|||
* is already in the middle of another one. |
|||
* |
|||
* @note in,out fields are labelled as such because they get updated by update_identity()/myself() |
|||
* and have group flags added. group_identity may have its user_id freed and replaced |
|||
* with the canonical own user id. |
|||
* |
|||
*/ |
|||
DYNAMIC_API PEP_STATUS adapter_group_create( |
|||
PEP_SESSION session, |
|||
pEp_identity *group_identity, |
|||
pEp_identity *manager, |
|||
identity_list *memberlist, |
|||
pEp_group **group |
|||
); |
|||
|
|||
|
|||
/**
|
|||
* <!-- adapter_group_join() --> |
|||
* |
|||
* @brief Join a group for which we have received an invitation, marking |
|||
* our own membership in the database for the group and sending the manager |
|||
* a confirmation of the acceptance of the invitation |
|||
* |
|||
* @param[in] session associated session object |
|||
* @param[in] group_identity the pEp_identity object representing the group. Must contain at least |
|||
* a user_id and address |
|||
* @param[in] as_member the pEp_identity object representing the own identity we want to use to |
|||
* join the group. This must match the identity which was invited to the group. |
|||
* Must contain a user_id and address. |
|||
* |
|||
* @retval PEP_STATUS_OK on success |
|||
* error on failure |
|||
* |
|||
* @ownership FIXME |
|||
* |
|||
* |
|||
*/ |
|||
DYNAMIC_API PEP_STATUS adapter_group_join( |
|||
PEP_SESSION session, |
|||
pEp_identity *group_identity, |
|||
pEp_identity *as_member |
|||
); |
|||
|
|||
/**
|
|||
* <!-- adapter_group_dissolve() --> |
|||
* |
|||
* @brief Dissolve a group, revoke its key, notify all members of the dissolution and |
|||
* revocation, and mark the group as inactive in the database |
|||
* |
|||
* @param[in] session associated session object |
|||
* @param[in] group_identity the pEp_identity object representing the group. Must contain at least |
|||
* a user_id and address |
|||
* @param[in] manager the pEp_identity object representing the group's manager. Must contain |
|||
* a user_id and address, and there must be a default key for the manager |
|||
* present in the database |
|||
* |
|||
* @retval PEP_STATUS_OK on success |
|||
* error on failure |
|||
* |
|||
* @ownership FIXME |
|||
* |
|||
* @warning For recipients to accept the dissolution, the sender/manager key used must be a key that they |
|||
* have a trust entry for. |
|||
*/ |
|||
DYNAMIC_API PEP_STATUS adapter_group_dissolve( |
|||
PEP_SESSION session, |
|||
pEp_identity *group_identity, |
|||
pEp_identity *manager |
|||
); |
|||
|
|||
/**
|
|||
* <!-- adapter_group_invite_member() --> |
|||
* |
|||
* @brief Invite a member to an extant group, marking the member as invited in the database and |
|||
* sending out an invitation to said member |
|||
* |
|||
* @param[in] session associated session object |
|||
* @param[in] group_identity the pEp_identity object representing the group. Must contain at least |
|||
* a user_id and address |
|||
* @param[in] group_member the pEp_identity object representing the member to invite. Must contain |
|||
* a user_id and address, and there must be a default key for the member |
|||
* present in the database |
|||
* |
|||
* @retval PEP_STATUS_OK on success |
|||
* error on failure |
|||
* |
|||
* @ownership FIXME |
|||
* |
|||
* @note This generates a GroupCreate message even though the group already exists - this is because |
|||
* this is the accepted message format for invitations to potential members |
|||
* |
|||
*/ |
|||
DYNAMIC_API PEP_STATUS adapter_group_invite_member( |
|||
PEP_SESSION session, |
|||
pEp_identity *group_identity, |
|||
pEp_identity *group_member |
|||
); |
|||
|
|||
/**
|
|||
* <!-- adapter_group_remove_member() --> |
|||
* |
|||
* @brief Remove a member from a group, deleting the member from the member list and executing a key |
|||
* reset on the group identity |
|||
* |
|||
* @param[in] session associated session object |
|||
* @param[in] group_identity the pEp_identity object representing the group. Must contain at least |
|||
* a user_id and address |
|||
* @param[in] group_member the pEp_identity object representing the member to remove. Must contain |
|||
* a user_id and address |
|||
* |
|||
* @retval PEP_STATUS_OK on success |
|||
* error on failure |
|||
* |
|||
* @ownership FIXME |
|||
* |
|||
* @todo Revamp implementation and execute key reset |
|||
* |
|||
*/ |
|||
PEP_STATUS adapter_group_remove_member( |
|||
PEP_SESSION session, |
|||
pEp_identity *group_identity, |
|||
pEp_identity *group_member |
|||
); |
|||
|
|||
/**
|
|||
* <!-- adapter_group_rating() --> |
|||
* |
|||
* @brief Get the rating for this group - if the caller is the manager, this will return the aggregate rating |
|||
* of group members. For members, this will return the rating of the group_identity |
|||
* |
|||
* @param[in] session associated session object |
|||
* @param[in] group_identity the pEp_identity object representing the group. Must contain at least |
|||
* a user_id and address |
|||
* @param[in] manager the pEp_identity object representing the member to remove. Must contain |
|||
* a user_id and address |
|||
* @param[out] rating the group rating |
|||
* |
|||
* @retval PEP_STATUS_OK on success |
|||
* error on failure |
|||
* |
|||
* @ownership FIXME |
|||
* |
|||
*/ |
|||
DYNAMIC_API PEP_STATUS adapter_group_rating( |
|||
PEP_SESSION session, |
|||
pEp_identity *group_identity, |
|||
pEp_identity *manager, |
|||
PEP_rating *rating |
|||
); |
|||
|
|||
|
|||
|
|||
/*************************************************************************************************
|
|||
* Group query functions |
|||
*************************************************************************************************/ |
|||
|
|||
/**
|
|||
* <!-- group_query_groups() --> |
|||
* |
|||
* @brief queries the list manager which groups currently exist. |
|||
* |
|||
* @param[in] session associated session object |
|||
* @param[out] groups list of pEp_identity representing |
|||
* all group identities that currently exist. |
|||
* |
|||
* @retval PEP_STATUS_OK on success |
|||
* error on failure |
|||
* |
|||
* @ownership ownership of all parameters goes to the caller |
|||
* |
|||
*/ |
|||
|
|||
//DYNAMIC_API PEP_STATUS group_query_groups(
|
|||
// PEP_SESSION session,
|
|||
// identity_list **groups
|
|||
//);
|
|||
|
|||
/**
|
|||
* <!-- group_query_manager() --> |
|||
* |
|||
* @brief queries the list manager for the group manager of a given group. |
|||
* |
|||
* @param[in] session associated session object |
|||
* @param[in] group pEp_Identity representing the group identity in question |
|||
* @param[out] manager pEp_identity representing the group manager for "group" |
|||
* |
|||
* @retval PEP_STATUS_OK on success |
|||
* error on failure |
|||
* |
|||
* @ownership ownership of all parameters goes to the caller |
|||
* |
|||
*/ |
|||
|
|||
//DYNAMIC_API PEP_STATUS group_query_manager(
|
|||
// PEP_SESSION session,
|
|||
// const pEp_identity *const group,
|
|||
// pEp_identity **manager
|
|||
//);
|
|||
|
|||
/**
|
|||
* <!-- group_query_members() --> |
|||
* |
|||
* @brief queries the list manager for all members of a given group. |
|||
* |
|||
* @param[in] session associated session object |
|||
* @param[in] group pEp_Identity representing the group identity in question |
|||
* @param[out] members list of pEp_identity representing all the members of "group" |
|||
* |
|||
* @retval PEP_STATUS_OK on success |
|||
* error on failure |
|||
* |
|||
* @ownership ownership of all parameters goes to the caller |
|||
* |
|||
*/ |
|||
|
|||
//DYNAMIC_API PEP_STATUS group_query_members(
|
|||
// PEP_SESSION session,
|
|||
// const pEp_identity *const group,
|
|||
// identity_list **members
|
|||
//);
|
|||
|
|||
|
|||
#ifdef __cplusplus |
|||
}; |
|||
#endif |
|||
|
|||
#endif //LIBPEPADAPTER_GROUP_HH
|
@ -0,0 +1,165 @@ |
|||
// This file is under GNU General Public License 3.0
|
|||
// see LICENSE.txt
|
|||
|
|||
#include "utils.hh" |
|||
|
|||
#include <iostream> |
|||
|
|||
#include <pEp/identity_list.h> |
|||
|
|||
#include "../../src/Adapter.hh" |
|||
#include "../../src/adapter_group.h" |
|||
|
|||
using namespace std; |
|||
using namespace pEp; |
|||
|
|||
namespace pEp { |
|||
namespace Test { |
|||
namespace Log { |
|||
void logH1(string msg) |
|||
{ |
|||
char decoration{ '=' }; |
|||
cout << endl |
|||
<< endl |
|||
<< std::string(30, decoration) << ' ' << msg << ' ' |
|||
<< std::string(30, decoration) << endl; |
|||
} |
|||
|
|||
void logH2(string msg) |
|||
{ |
|||
char decoration{ '-' }; |
|||
cout << endl |
|||
<< std::string(10, decoration) << ' ' << msg << ' ' |
|||
<< std::string(10, decoration) << endl; |
|||
} |
|||
} // namespace Log
|
|||
|
|||
namespace Utils { |
|||
string identity_to_string(::pEp_identity* ident, bool full, int indent) |
|||
{ |
|||
|
|||
stringstream builder; |
|||
if (ident != nullptr) { |
|||
if (full) { |
|||
builder << endl; |
|||
builder << std::string(indent, '\t') << "{" << endl; |
|||
indent++; |
|||
builder << std::string(indent, '\t') << "address: " |
|||
<< (ident->address != nullptr ? ident->address : "NULL") << endl; |
|||
builder << std::string(indent, '\t') << "user_id: " |
|||
<< (ident->user_id != nullptr ? ident->user_id : "NULL") << endl; |
|||
builder << std::string(indent, '\t') << "username: " |
|||
<< (ident->username != nullptr ? ident->username : "NULL") << endl; |
|||
builder << std::string(indent, '\t') |
|||
<< "fpr: " << (ident->fpr != nullptr ? ident->fpr : "NULL") << endl; |
|||
builder << std::string(indent, '\t') << "comm_type: " << ident->comm_type |
|||
<< endl; |
|||
builder << std::string(indent, '\t') |
|||
<< "lang: " << static_cast<string>(ident->lang) << endl; |
|||
builder << std::string(indent, '\t') << "me: " << ident->me << endl; |
|||
builder << std::string(indent, '\t') << "major_ver: " << ident->major_ver |
|||
<< endl; |
|||
builder << std::string(indent, '\t') << "minor_ver: " << ident->minor_ver |
|||
<< endl; |
|||
builder << std::string(indent, '\t') << "enc_format: " << ident->enc_format |
|||
<< endl; |
|||
builder << std::string(indent, '\t') << "flags: " << ident->flags << endl; |
|||
indent--; |
|||
builder << std::string(indent, '\t') << "}"; |
|||
} else { |
|||
builder << "{ " << (ident->address != nullptr ? ident->address : "NULL") |
|||
<< "/" << (ident->user_id != nullptr ? ident->user_id : "NULL") |
|||
<< "/" << (ident->username != nullptr ? ident->username : "NULL") |
|||
<< "/" << (ident->fpr != nullptr ? ident->fpr : "NULL") << " }"; |
|||
} |
|||
} else { |
|||
builder << "NULL"; |
|||
} |
|||
|
|||
return builder.str(); |
|||
} |
|||
|
|||
std::string identitylist_to_string(::identity_list* idl, bool full, int indent) |
|||
{ |
|||
stringstream builder; |
|||
if (idl != nullptr) { |
|||
builder << endl; |
|||
builder << std::string(indent, '\t') << "[" << endl; |
|||
indent++; |
|||
for (::identity_list* curr = idl; curr != nullptr; curr = curr->next) { |
|||
builder << identity_to_string(curr->ident, full, indent) << endl; |
|||
} |
|||
indent--; |
|||
builder << std::string(indent, '\t') << "]"; |
|||
} else { |
|||
builder << "NULL"; |
|||
} |
|||
|
|||
return builder.str(); |
|||
} |
|||
|
|||
string member_to_string(::pEp_member* member, bool full, int indent) |
|||
{ |
|||
stringstream builder; |
|||
if (member != nullptr) { |
|||
builder << std::string(indent, '\t') << "{" << endl; |
|||
indent++; |
|||
builder << std::string(indent, '\t') |
|||
<< "ident: " << identity_to_string(member->ident, full, indent) << endl; |
|||
builder << std::string(indent, '\t') << "joined: " << member->joined << endl; |
|||
indent--; |
|||
builder << std::string(indent, '\t') << "}"; |
|||
} else { |
|||
builder << "NULL"; |
|||
} |
|||
|
|||
return builder.str(); |
|||
} |
|||
|
|||
string memberlist_to_string(::member_list* mbl, bool full, int indent) |
|||
{ |
|||
stringstream builder; |
|||
if (mbl != nullptr) { |
|||
builder << endl; |
|||
builder << std::string(indent, '\t') << "[" << endl; |
|||
indent++; |
|||
for (member_list* curr_member = mbl; curr_member != nullptr; |
|||
curr_member = curr_member->next) { |
|||
builder << member_to_string(curr_member->member, full, indent) << endl; |
|||
} |
|||
indent--; |
|||
builder << std::string(indent, '\t') << "]"; |
|||
} else { |
|||
builder << "NULL"; |
|||
} |
|||
|
|||
return builder.str(); |
|||
} |
|||
|
|||
string group_to_string(::pEp_group* group, bool full, int indent) |
|||
{ |
|||
stringstream builder; |
|||
if (group != nullptr) { |
|||
builder << endl; |
|||
builder << std::string(indent, '\t') << "{" << endl; |
|||
indent++; |
|||
builder << std::string(indent, '\t') << "group_identity: " |
|||
<< identity_to_string(group->group_identity, full, indent) << endl; |
|||
builder << std::string(indent, '\t') |
|||
<< "manager: " << identity_to_string(group->manager, full, indent) |
|||
<< endl; |
|||
builder << std::string(indent, '\t') << "active: " << group->active << endl; |
|||
builder << std::string(indent, '\t') |
|||
<< "members: " << memberlist_to_string(group->members, full, indent) |
|||
<< endl; |
|||
indent--; |
|||
builder << std::string(indent, '\t') << "]"; |
|||
} else { |
|||
builder << "NULL"; |
|||
} |
|||
|
|||
return builder.str(); |
|||
} |
|||
} // namespace Utils
|
|||
} // namespace Test
|
|||
} // namespace pEp
|
@ -0,0 +1,27 @@ |
|||
// This file is under GNU General Public License 3.0
|
|||
// see LICENSE.txt
|
|||
|
|||
#ifndef LIBPEPADAPTER_UTILS_HH |
|||
#define LIBPEPADAPTER_UTILS_HH |
|||
|
|||
#include <string> |
|||
#include <pEp/message.h> |
|||
#include <pEp/identity_list.h> |
|||
#include <pEp/group.h> |
|||
|
|||
namespace pEp { |
|||
namespace Test { |
|||
namespace Log { |
|||
void logH1(std::string msg); |
|||
void logH2(std::string msg); |
|||
} |
|||
namespace Utils { |
|||
std::string identity_to_string(::pEp_identity* ident, bool full = true, int indent = 0); |
|||
std::string identitylist_to_string(::identity_list * idl, bool full = true, int indent = 0); |
|||
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); |
|||
} |
|||
} // namespace Test
|
|||
} // namespace pEp
|
|||
#endif |
@ -0,0 +1,221 @@ |
|||
// This file is under GNU General Public License 3.0
|
|||
// see LICENSE.txt
|
|||
|
|||
#include "framework/framework.hh" |
|||
#include "framework/utils.hh" |
|||
|
|||
#include <iostream> |
|||
|
|||
#include "../src/Adapter.hh" |
|||
#include "../src/adapter_group.h" |
|||
#include "../src/status_to_string.hh" |
|||
|
|||
using namespace std; |
|||
using namespace pEp; |
|||
using namespace pEp::Test::Log; |
|||
|
|||
bool debug_info_full = true; |
|||
::pEp_identity* alice = nullptr; |
|||
::pEp_identity* bob = nullptr; |
|||
::pEp_identity* carol = nullptr; |
|||
::pEp_identity* grp_ident = nullptr; |
|||
::PEP_STATUS status; |
|||
|
|||
/*
|
|||
* Callbacks |
|||
*/ |
|||
|
|||
::PEP_STATUS test_messageToSend(::message* _msg) |
|||
{ |
|||
cout << "called" << endl; |
|||
cout << Test::make_pEp_msg(Test::make_message(_msg)); |
|||
return PEP_STATUS_OK; |
|||
} |
|||
|
|||
::PEP_STATUS test_notifyHandshake(::pEp_identity* _me, ::pEp_identity* _partner, sync_handshake_signal signal) |
|||
{ |
|||
cout << "called" << endl; |
|||
cout << "me: " << Test::Utils::identity_to_string(_me, false) << endl; |
|||
cout << "partner: " << Test::Utils::identity_to_string(_partner, false) << endl; |
|||
cout << "Signal: " << signal << endl; |
|||
|
|||
return PEP_STATUS_OK; |
|||
} |
|||
|
|||
/*
|
|||
* Test Units |
|||
*/ |
|||
|
|||
void test_create_alice_me() |
|||
{ |
|||
logH2("test_create_alice_me"); |
|||
alice = ::new_identity("alice@peptest.ch", NULL, "23", "Alice"); |
|||
assert(alice); |
|||
alice->lang[0] = 'e'; |
|||
alice->lang[1] = 'n'; |
|||
status = ::myself(Adapter::session(), alice); |
|||
cout << "STATUS: " << status_to_string(status) << endl; |
|||
assert(!status); |
|||
cout << "Alice:" << Test::Utils::identity_to_string(alice, debug_info_full) << endl; |
|||
} |
|||
|
|||
void test_create_bob_partner() |
|||
{ |
|||
logH2("test_create_bob_partner"); |
|||
bob = ::new_identity("bob@peptest.ch", NULL, PEP_OWN_USERID, "Bob"); |
|||
assert(bob); |
|||
bob->lang[0] = 'c'; |
|||
bob->lang[1] = 'r'; |
|||
status = ::update_identity(Adapter::session(), bob); |
|||
cout << "STATUS: " << status_to_string(status) << endl; |
|||
assert(!status); |
|||
cout << "Bob:" << Test::Utils::identity_to_string(bob, debug_info_full) << endl; |
|||
} |
|||
|
|||
void test_create_carol_partner() |
|||
{ |
|||
logH2("test_create_carol_partner"); |
|||
carol = ::new_identity("carol@peptest.ch", NULL, PEP_OWN_USERID, "Carol"); |
|||
assert(carol); |
|||
carol->lang[0] = 'f'; |
|||
carol->lang[1] = 'n'; |
|||
status = ::update_identity(Adapter::session(), carol); |
|||
cout << "STATUS: " << status_to_string(status) << endl; |
|||
assert(!status); |
|||
cout << "Carol:" << Test::Utils::identity_to_string(carol, debug_info_full) << endl; |
|||
} |
|||
|
|||
void test_setup_and_start_sync() |
|||
{ |
|||
logH2("test_setup_and_start_sync"); |
|||
Adapter::sync_initialize(Adapter::SyncModes::Async, &test_messageToSend, &test_notifyHandshake, false); |
|||
} |
|||
|
|||
void test_group_create(::identity_list* idl) |
|||
{ |
|||
logH2("test_group_create"); |
|||
cout << "IDL: " << Test::Utils::identitylist_to_string(idl, debug_info_full) << endl; |
|||
|
|||
cout << "create group identity" << endl; |
|||
grp_ident = ::new_identity("group1@peptest.ch", NULL, "432", "group1"); |
|||
assert(grp_ident); |
|||
status = ::myself(Adapter::session(), grp_ident); |
|||
cout << "STATUS: " << status_to_string(status) << endl; |
|||
assert(!status); |
|||
cout << "grp_ident:" << Test::Utils::identity_to_string(grp_ident, debug_info_full) << endl; |
|||
|
|||
cout << "adapter_group_create()" << endl; |
|||
::pEp_group* pep_grp1 = nullptr; |
|||
status = ::adapter_group_create(Adapter::session(), grp_ident, alice, idl, &pep_grp1); |
|||
cout << "STATUS: " << status_to_string(status) << endl; |
|||
assert(!status); |
|||
assert(pep_grp1); |
|||
cout << "GRP: " << Test::Utils::group_to_string(pep_grp1, debug_info_full) << endl; |
|||
} |
|||
|
|||
void test_group_invite_member(::pEp_identity* ident) |
|||
{ |
|||
logH2("test_group_invite_member"); |
|||
status = ::adapter_group_invite_member(Adapter::session(), grp_ident, ident); |
|||
cout << "STATUS: " << status_to_string(status) << endl; |
|||
assert(!status); |
|||
} |
|||
|
|||
void test_group_join(::pEp_identity* ident) |
|||
{ |
|||
logH2("test_group_join"); |
|||
status = ::adapter_group_join(Adapter::session(), grp_ident, ident); |
|||
cout << "STATUS: " << status_to_string(status) << endl; |
|||
assert(!status); |
|||
} |
|||
|
|||
void test_group_remove_member(::pEp_identity* ident) |
|||
{ |
|||
logH2("test_group_remove_member"); |
|||
status = ::adapter_group_remove_member(Adapter::session(), grp_ident, ident); |
|||
cout << "STATUS: " << status_to_string(status) << endl; |
|||
assert(!status); |
|||
} |
|||
|
|||
void test_group_rating() |
|||
{ |
|||
logH2("test_group_rating"); |
|||
// Rating
|
|||
::PEP_rating* rating = nullptr; |
|||
cout << "adapter_group_rating()" << endl; |
|||
status = ::group_rating(Adapter::session(), grp_ident, alice, rating); |
|||
cout << "STATUS: " << status_to_string(status) << endl; |
|||
assert(!status); |
|||
cout << "Rating: " << rating << endl; |
|||
} |
|||
|
|||
void test_group_dissolve() |
|||
{ |
|||
logH2("test_group_dissolve"); |
|||
status = ::adapter_group_dissolve(Adapter::session(), grp_ident, alice); |
|||
cout << "STATUS: " << status_to_string(status) << endl; |
|||
assert(!status); |
|||
} |
|||
|
|||
/*
|
|||
* Update functions |
|||
* ---------------- |
|||
* Test procedure: |
|||
* 1. Create group |
|||
* - group_create(Alice) |
|||
* 2. Add Bob |
|||
* - group_invite_member(Bob) |
|||
* - group_join(Bob) |
|||
* 3. Add Carol |
|||
* - group_invite_member(Carol) |
|||
* - group_join(Carol) |
|||
* 4. Remove Carol |
|||
* - group_remove_member(Carol) |
|||
* 5. Rating |
|||
* - group_rating() (Just test once, to see it is generally working) |
|||
* 6. Dissolve |
|||
* - group_dissolve() |
|||
* |
|||
* Query functions |
|||
* --------------- |
|||
* Always test all the query functions for correctness between every step above. |
|||
* group_query_groups() |
|||
* group_query_manager() |
|||
* group_query_members |
|||
*/ |
|||
|
|||
|
|||
int main(int argc, char** argv) |
|||
{ |
|||
Test::setup(argc, argv); |
|||
Adapter::pEpLog::set_enabled(false); |
|||
debug_info_full = true; |
|||
|
|||
// Setup Test Context
|
|||
test_create_alice_me(); |
|||
test_create_bob_partner(); |
|||
test_create_carol_partner(); |
|||
test_setup_and_start_sync(); |
|||
|
|||
|
|||
logH1("1. Create group"); |
|||
::identity_list* initial_memberlist = nullptr; |
|||
initial_memberlist = new_identity_list(bob); |
|||
::identity_list_add(initial_memberlist, carol); |
|||
test_group_create(initial_memberlist); |
|||
logH1("2. Add Bob"); |
|||
// test_group_invite_member(bob); // Fails
|
|||
// test_group_join(bob); // Fails
|
|||
logH1("3. Add Carol"); |
|||
// test_group_invite_member(carol);
|
|||
// test_group_join(carol);
|
|||
logH1("4. Remove Carol"); |
|||
// test_group_remove_member(carol);
|
|||
logH1("5. Rating"); |
|||
// test_group_rating(); // Failing
|
|||
logH1("6. Dissolve"); |
|||
test_group_dissolve(); |
|||
|
|||
Adapter::shutdown(); |
|||
return 0; |
|||
} |
Loading…
Reference in new issue