From cbeb640237da883f25535fcc34e18264ef08beaf Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 16 Mar 2021 16:58:42 +0100 Subject: [PATCH 01/24] LIB-11: Add group query API (1st draft) --- adapter_group.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 adapter_group.h diff --git a/adapter_group.h b/adapter_group.h new file mode 100644 index 0000000..5378598 --- /dev/null +++ b/adapter_group.h @@ -0,0 +1,83 @@ +// This file is under GNU General Public License 3.0 +// see LICENSE.txt + +#ifndef LIBPEPADAPTER_GROUP_HH +#define LIBPEPADAPTER_GROUP_HH + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * + * + * @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 query_groups( + PEP_SESSION session, + identity_list **groups + ); + +/** + * + * + * @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 query_group_manager( + PEP_SESSION session, + pEp_identity *group, + pEp_identity **manager + ); + +/** + * + * + * @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 query_group_members( + PEP_SESSION session, + pEp_identity *group, + identity_list **members + ); + + +#ifdef __cplusplus +}; +#endif + +#endif //LIBPEPADAPTER_GROUP_HH \ No newline at end of file From 28d80bf2b194ffc58c1fd3b31ed3d9c342611edf Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 16 Mar 2021 17:13:30 +0100 Subject: [PATCH 02/24] LIB-11: Add const to [in] params --- adapter_group.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adapter_group.h b/adapter_group.h index 5378598..4e30365 100644 --- a/adapter_group.h +++ b/adapter_group.h @@ -49,7 +49,7 @@ DYNAMIC_API PEP_STATUS query_groups( DYNAMIC_API PEP_STATUS query_group_manager( PEP_SESSION session, - pEp_identity *group, + const pEp_identity * const group, pEp_identity **manager ); @@ -71,7 +71,7 @@ DYNAMIC_API PEP_STATUS query_group_manager( DYNAMIC_API PEP_STATUS query_group_members( PEP_SESSION session, - pEp_identity *group, + const pEp_identity * const group, identity_list **members ); From 8d6be151adb20c836761c848c830f1dae3d29275 Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 16 Mar 2021 17:20:21 +0100 Subject: [PATCH 03/24] LIB-11: Add "Group management functions" from pEpEngine/group.h --- adapter_group.h | 185 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) diff --git a/adapter_group.h b/adapter_group.h index 4e30365..83fec23 100644 --- a/adapter_group.h +++ b/adapter_group.h @@ -10,6 +10,191 @@ extern "C" { #endif +/************************************************************************************************* + * Group management functions + *************************************************************************************************/ + +/** + * + * + * @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] 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 + * @param[in] memberlist list of group members + * @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 FIXME + * + * + * + */ +DYNAMIC_API PEP_STATUS group_create( + PEP_SESSION session, + pEp_identity *group_identity, + pEp_identity *manager, + identity_list *memberlist, + pEp_group **group + ); + +/** + * + * + * @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 group_join( + PEP_SESSION session, + pEp_identity *group_identity, + pEp_identity *as_member + ); + +/** + * + * + * @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 group_dissolve( + PEP_SESSION session, + pEp_identity *group_identity, + pEp_identity *manager + ); + +/** + * + * + * @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 group_invite_member( + PEP_SESSION session, + pEp_identity *group_identity, + pEp_identity *group_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 group_remove_member( + PEP_SESSION session, + pEp_identity *group_identity, + pEp_identity *group_member + ); + +/** + * + * + * @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 group_rating( + PEP_SESSION session, + pEp_identity *group_identity, + pEp_identity *manager, + PEP_rating *rating + ); + + + +/************************************************************************************************* + * Group query functions + *************************************************************************************************/ + /** * * From f33262f152a120dac42a6ac2198d2505ea7fd146 Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 16 Mar 2021 17:50:18 +0100 Subject: [PATCH 04/24] LIB-11: use prefix "group_" for query functions / use prefix "adapter_" for "wrapped" Group management functions --- adapter_group.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/adapter_group.h b/adapter_group.h index 83fec23..0110cfb 100644 --- a/adapter_group.h +++ b/adapter_group.h @@ -15,7 +15,7 @@ extern "C" { *************************************************************************************************/ /** - * + * * * @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). @@ -47,7 +47,7 @@ extern "C" { * * */ -DYNAMIC_API PEP_STATUS group_create( +DYNAMIC_API PEP_STATUS adapter_group_create( PEP_SESSION session, pEp_identity *group_identity, pEp_identity *manager, @@ -56,7 +56,7 @@ DYNAMIC_API PEP_STATUS group_create( ); /** - * + * * * @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 @@ -76,14 +76,14 @@ DYNAMIC_API PEP_STATUS group_create( * * */ -DYNAMIC_API PEP_STATUS group_join( +DYNAMIC_API PEP_STATUS adapter_group_join( PEP_SESSION session, pEp_identity *group_identity, pEp_identity *as_member ); /** - * + * * * @brief Dissolve a group, revoke its key, notify all members of the dissolution and * revocation, and mark the group as inactive in the database @@ -103,14 +103,14 @@ DYNAMIC_API PEP_STATUS group_join( * @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 group_dissolve( +DYNAMIC_API PEP_STATUS adapter_group_dissolve( PEP_SESSION session, pEp_identity *group_identity, pEp_identity *manager ); /** - * + * * * @brief Invite a member to an extant group, marking the member as invited in the database and * sending out an invitation to said member @@ -131,14 +131,14 @@ DYNAMIC_API PEP_STATUS group_dissolve( * this is the accepted message format for invitations to potential members * */ -DYNAMIC_API PEP_STATUS group_invite_member( +DYNAMIC_API PEP_STATUS adapter_group_invite_member( PEP_SESSION session, pEp_identity *group_identity, pEp_identity *group_member ); /** - * + * * * @brief Remove a member from a group, deleting the member from the member list and executing a key * reset on the group identity @@ -157,14 +157,14 @@ DYNAMIC_API PEP_STATUS group_invite_member( * @todo Revamp implementation and execute key reset * */ -PEP_STATUS group_remove_member( +PEP_STATUS adapter_group_remove_member( PEP_SESSION session, pEp_identity *group_identity, pEp_identity *group_member ); /** - * + * * * @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 @@ -182,7 +182,7 @@ PEP_STATUS group_remove_member( * @ownership FIXME * */ -DYNAMIC_API PEP_STATUS group_rating( +DYNAMIC_API PEP_STATUS adapter_group_rating( PEP_SESSION session, pEp_identity *group_identity, pEp_identity *manager, @@ -196,7 +196,7 @@ DYNAMIC_API PEP_STATUS group_rating( *************************************************************************************************/ /** - * + * * * @brief queries the list manager which groups currently exist. * @@ -211,13 +211,13 @@ DYNAMIC_API PEP_STATUS group_rating( * */ -DYNAMIC_API PEP_STATUS query_groups( +DYNAMIC_API PEP_STATUS group_query_groups( PEP_SESSION session, identity_list **groups ); /** - * + * * * @brief queries the list manager for the group manager of a given group. * @@ -232,14 +232,14 @@ DYNAMIC_API PEP_STATUS query_groups( * */ -DYNAMIC_API PEP_STATUS query_group_manager( +DYNAMIC_API PEP_STATUS group_query_manager( PEP_SESSION session, const pEp_identity * const group, pEp_identity **manager ); /** - * + * * * @brief queries the list manager for all members of a given group. * @@ -254,7 +254,7 @@ DYNAMIC_API PEP_STATUS query_group_manager( * */ -DYNAMIC_API PEP_STATUS query_group_members( +DYNAMIC_API PEP_STATUS group_query_members( PEP_SESSION session, const pEp_identity * const group, identity_list **members From 91583a93fdbe57d3e7d0944d89741259d88285cb Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 18 Mar 2021 01:48:02 +0100 Subject: [PATCH 05/24] minor formatting only (auto) --- adapter_group.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/adapter_group.h b/adapter_group.h index 0110cfb..2402d7c 100644 --- a/adapter_group.h +++ b/adapter_group.h @@ -44,16 +44,16 @@ extern "C" { * * @ownership FIXME * - * + * TODO: member_list *memberlist -> change to identity_list * */ DYNAMIC_API PEP_STATUS adapter_group_create( PEP_SESSION session, pEp_identity *group_identity, pEp_identity *manager, - identity_list *memberlist, + member_list *memberlist, pEp_group **group - ); +); /** * @@ -80,7 +80,7 @@ DYNAMIC_API PEP_STATUS adapter_group_join( PEP_SESSION session, pEp_identity *group_identity, pEp_identity *as_member - ); +); /** * @@ -107,7 +107,7 @@ DYNAMIC_API PEP_STATUS adapter_group_dissolve( PEP_SESSION session, pEp_identity *group_identity, pEp_identity *manager - ); +); /** * @@ -135,7 +135,7 @@ DYNAMIC_API PEP_STATUS adapter_group_invite_member( PEP_SESSION session, pEp_identity *group_identity, pEp_identity *group_member - ); +); /** * @@ -161,7 +161,7 @@ PEP_STATUS adapter_group_remove_member( PEP_SESSION session, pEp_identity *group_identity, pEp_identity *group_member - ); +); /** * @@ -187,7 +187,7 @@ DYNAMIC_API PEP_STATUS adapter_group_rating( pEp_identity *group_identity, pEp_identity *manager, PEP_rating *rating - ); +); @@ -214,7 +214,7 @@ DYNAMIC_API PEP_STATUS adapter_group_rating( DYNAMIC_API PEP_STATUS group_query_groups( PEP_SESSION session, identity_list **groups - ); +); /** * @@ -234,9 +234,9 @@ DYNAMIC_API PEP_STATUS group_query_groups( DYNAMIC_API PEP_STATUS group_query_manager( PEP_SESSION session, - const pEp_identity * const group, + const pEp_identity *const group, pEp_identity **manager - ); +); /** * @@ -256,9 +256,9 @@ DYNAMIC_API PEP_STATUS group_query_manager( DYNAMIC_API PEP_STATUS group_query_members( PEP_SESSION session, - const pEp_identity * const group, + const pEp_identity *const group, identity_list **members - ); +); #ifdef __cplusplus From 69367324f96803bd7674ee5d0e7c5b051fd908b5 Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 18 Mar 2021 01:48:31 +0100 Subject: [PATCH 06/24] adapter_group.cc - initial draft --- adapter_group.cc | 105 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 adapter_group.cc diff --git a/adapter_group.cc b/adapter_group.cc new file mode 100644 index 0000000..572704c --- /dev/null +++ b/adapter_group.cc @@ -0,0 +1,105 @@ +// This file is under GNU General Public License 3.0 +// see LICENSE.txt +#include +#include "adapter_group.h" + +#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, + member_list *memberlist, + pEp_group **group +) +{ + 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 +) +{ + 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 +) +{ + 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 +) +{ + 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 +) +{ + 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 +) +{ + return ::group_rating(session, group_identity, manager, rating); +} + +/************************************************************************************************* + * Group query functions + *************************************************************************************************/ + + +DYNAMIC_API PEP_STATUS group_query_groups( + PEP_SESSION session, + identity_list **groups +) +{ + return PEP_STATUS_OK; +} + +DYNAMIC_API PEP_STATUS group_query_manager( + PEP_SESSION session, + const pEp_identity *const group, + pEp_identity **manager +) +{ + return PEP_STATUS_OK; +} + +DYNAMIC_API PEP_STATUS group_query_members( + PEP_SESSION session, + const pEp_identity *const group, + identity_list **members +) +{ + return PEP_STATUS_OK; +} + +#ifdef __cplusplus +} +#endif + From e87cbc18dd337dff549a6694434a87e2bb4774cf Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 7 Apr 2021 16:40:45 +0200 Subject: [PATCH 07/24] move group module to src --- adapter_group.cc => src/adapter_group.cc | 0 adapter_group.h => src/adapter_group.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename adapter_group.cc => src/adapter_group.cc (100%) rename adapter_group.h => src/adapter_group.h (100%) diff --git a/adapter_group.cc b/src/adapter_group.cc similarity index 100% rename from adapter_group.cc rename to src/adapter_group.cc diff --git a/adapter_group.h b/src/adapter_group.h similarity index 100% rename from adapter_group.h rename to src/adapter_group.h From 07b4ee6e976c6e51744e1769546dca494b796988 Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 8 Apr 2021 22:16:58 +0200 Subject: [PATCH 08/24] tests: create subdir "framework" --- src/Makefile | 2 +- src/adapter_group.h | 2 ++ test/Makefile | 19 +++++++++++++------ test/{ => framework}/framework.cc | 6 +++--- test/{ => framework}/framework.hh | 4 ++-- test/test_adapter.cc | 7 ++++--- test/test_adapter_cxx.cc | 6 +++--- test/test_ensure_passphrase.cc | 12 ++++++------ test/test_leave_device_group.cc | 9 +++++---- test/test_message_cache.cc | 8 +++++--- test/test_passphrase_cache.cc | 10 +++++----- test/test_semaphore.cc | 3 ++- 12 files changed, 51 insertions(+), 37 deletions(-) rename test/{ => framework}/framework.cc (98%) rename test/{ => framework}/framework.hh (98%) diff --git a/src/Makefile b/src/Makefile index 2b3b74b..850134e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -6,7 +6,7 @@ include ../Makefile.conf SOURCE=$(wildcard *.cc) -HEADERS=$(wildcard *.hh *.hxx) +HEADERS=$(wildcard *.hh *.hxx *.h) OBJECTS=$(subst .cc,.o,$(SOURCE)) DEPENDS=$(subst .cc,.d,$(SOURCE)) CXXFLAGS+= -MMD -MP diff --git a/src/adapter_group.h b/src/adapter_group.h index 2402d7c..67919b7 100644 --- a/src/adapter_group.h +++ b/src/adapter_group.h @@ -4,6 +4,8 @@ #ifndef LIBPEPADAPTER_GROUP_HH #define LIBPEPADAPTER_GROUP_HH +#include +#include #ifdef __cplusplus extern "C" { diff --git a/test/Makefile b/test/Makefile index 7f6045f..62e81de 100644 --- a/test/Makefile +++ b/test/Makefile @@ -3,17 +3,24 @@ include ../Makefile.conf LDFLAGS=-L../src $(ENGINE_LIB) LDLIBS=-lstdc++ -lpEpEngine -lpEpAdapter CXXFLAGS:=-I../src -DENGINE_TEST=$(ENGINE_TEST) $(CXXFLAGS) -SRC=$(wildcard test_*.cc) -TST=$(subst .cc,,$(SRC)) -all: $(TST) +SRC_TEST=$(wildcard test_*.cc) +BIN_TEST=$(subst .cc,,$(SRC_TEST)) -$(TST): framework.o +SRC_FRAMEWORK=$(wildcard framework/*.cc) +OBJ_FRAMEWORK=$(subst .cc,.o,$(SRC_FRAMEWORK)) + +.PHONY: all clean rmtestdata + +all: $(BIN_TEST) + + +$(BIN_TEST): $(OBJ_FRAMEWORK) -.PHONY: clean rmtestdata clean: - rm -f $(TST) + rm -f $(BIN_TEST) + rm -f $(OBJ_FRAMEWORK) rm -Rf *.dSYM rm -f *.o rm -Rf /tmp/test_pEp.* diff --git a/test/framework.cc b/test/framework/framework.cc similarity index 98% rename from test/framework.cc rename to test/framework/framework.cc index 70bb0a1..ffb3e1c 100644 --- a/test/framework.cc +++ b/test/framework/framework.cc @@ -8,7 +8,6 @@ #include #include #include - #include #include #include @@ -22,7 +21,7 @@ #include #include -#include +#include "../src/Adapter.hh" pEp::Test::Transport pEp::Test::transport; std::string pEp::Test::path; @@ -74,8 +73,9 @@ namespace pEp { void setup(int argc, char **argv) { vector args{ (size_t)argc }; - for (int i = 0; i < argc; ++i) + for (int i = 0; i < argc; ++i) { args[i] = argv[i]; + } setup(args); } diff --git a/test/framework.hh b/test/framework/framework.hh similarity index 98% rename from test/framework.hh rename to test/framework/framework.hh index 9b04a6b..6052cec 100644 --- a/test/framework.hh +++ b/test/framework/framework.hh @@ -10,10 +10,10 @@ #include +using namespace std; + namespace pEp { namespace Test { - using namespace std; - // manually set up test void setup(vector &args); diff --git a/test/test_adapter.cc b/test/test_adapter.cc index ee0bd5e..b0e8954 100644 --- a/test/test_adapter.cc +++ b/test/test_adapter.cc @@ -1,18 +1,19 @@ // This file is under GNU General Public License 3.0 // see LICENSE.txt -#include "framework.hh" +#include "framework/framework.hh" #include #include #include #include -#include -#include #include #include #include +#include "../src/pEpLog.hh" +#include "../src/Adapter.hh" + using namespace std; using namespace pEp; diff --git a/test/test_adapter_cxx.cc b/test/test_adapter_cxx.cc index 9091abf..758c894 100644 --- a/test/test_adapter_cxx.cc +++ b/test/test_adapter_cxx.cc @@ -1,16 +1,16 @@ // This file is under GNU General Public License 3.0 // see LICENSE.txt -#include "framework.hh" +#include "framework/framework.hh" #include #include #include #include -#include #include -#include +#include "../src/Adapter.hh" +#include "../src/pEpLog.hh" using namespace pEp; diff --git a/test/test_ensure_passphrase.cc b/test/test_ensure_passphrase.cc index a4cfa9f..c1cda6d 100644 --- a/test/test_ensure_passphrase.cc +++ b/test/test_ensure_passphrase.cc @@ -1,6 +1,8 @@ // This file is under GNU General Public License 3.0 // see LICENSE.txt +#include "framework/framework.hh" + #include #include #include @@ -10,16 +12,14 @@ #include #include -#include "framework.hh" - -#include -#include -#include - #include #include #include +#include "../src/passphrase_cache.hh" +#include "../src/status_to_string.hh" +#include "../src/Adapter.hh" + using namespace pEp; using namespace std; diff --git a/test/test_leave_device_group.cc b/test/test_leave_device_group.cc index 33bdac5..6cfcf71 100644 --- a/test/test_leave_device_group.cc +++ b/test/test_leave_device_group.cc @@ -1,16 +1,17 @@ // This file is under GNU General Public License 3.0 // see LICENSE.txt +#include "framework/framework.hh" + #include #include #include -#include "framework.hh" -#include -#include - #include +#include "../src/callback_dispatcher.hh" +#include "../src/passphrase_cache.hh" + using namespace std; using namespace pEp; diff --git a/test/test_message_cache.cc b/test/test_message_cache.cc index 6c35b1b..fc240f9 100644 --- a/test/test_message_cache.cc +++ b/test/test_message_cache.cc @@ -1,13 +1,15 @@ // This file is under GNU General Public License 3.0 // see LICENSE.txt -#include "framework.hh" +#include "framework/framework.hh" + #include #include #include #include -#include -#include + +#include "../src/message_cache.hh" +#include "../src/Adapter.hh" using namespace std; using namespace pEp; diff --git a/test/test_passphrase_cache.cc b/test/test_passphrase_cache.cc index 32ca34e..016ea84 100644 --- a/test/test_passphrase_cache.cc +++ b/test/test_passphrase_cache.cc @@ -1,16 +1,16 @@ // This file is under GNU General Public License 3.0 // see LICENSE.txt -#include "framework.hh" +#include "framework/framework.hh" #include #include #include - #include -#include -#include -#include + +#include "../src/passphrase_cache.hh" +#include "../src/status_to_string.hh" +#include "../src/Adapter.hh" using namespace pEp; diff --git a/test/test_semaphore.cc b/test/test_semaphore.cc index 55196b6..1a5eafb 100644 --- a/test/test_semaphore.cc +++ b/test/test_semaphore.cc @@ -4,7 +4,8 @@ #include #include #include -#include "Semaphore.hh" + +#include "../src/Semaphore.hh" using namespace std; using namespace pEp; From b54f9d122b1f0a5bea0f4649215eadb29f4bea7e Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 8 Apr 2021 22:45:56 +0200 Subject: [PATCH 09/24] Build: Makefiles cleanup --- Makefile.conf | 27 +++++++-------------------- src/Makefile | 3 ++- test/Makefile | 19 +++++++++++++++---- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Makefile.conf b/Makefile.conf index ad57f57..bdb0226 100644 --- a/Makefile.conf +++ b/Makefile.conf @@ -7,16 +7,18 @@ HERE:=$(dir $(lastword $(MAKEFILE_LIST))) TARGET=libpEpAdapter.a +# Build config # Defaults DEBUG=1 PREFIX?=$(HOME) -ENGINE_LIB_PATH=$(PREFIX)/lib -ENGINE_INC_PATH=$(PREFIX)/include -CXXFLAGS+=-std=c++14 -fPIC +# Overrides +-include $(HERE)local.conf -# Build target -BUILD_FOR:=$(shell uname) +# Constants +CXXFLAGS+=-std=c++11 -fPIC +CXXFLAGS+=-I$(PREFIX)/include +LDFLAGS+=-L$(PREFIX)/lib ifneq (,$(findstring g++,$(CXX))) CXXFLAGS+=-fdiagnostics-color=always @@ -24,27 +26,12 @@ else ifneq (,$(findstring clang,$(CXX))) CXXFLAGS+=-fcolor-diagnostics endif - -######### Overrides ######### --include $(HERE)local.conf - ifeq ($(DEBUG),1) CXXFLAGS+=-g -O0 else CXXFLAGS+=-DNDEBUG=1 -O3 endif -# Add -L Prefixes to LIB/INC paths, -# if not already explicitly set in local.conf -ifndef ENGINE_LIB - ENGINE_LIB=-L$(ENGINE_LIB_PATH) -endif -ifndef ENGINE_INC - ENGINE_INC=-I$(ENGINE_INC_PATH) -endif - -CXXFLAGS += $(ENGINE_INC) - ifndef ENGINE_TEST ENGINE_TEST = \"$(HOME)/dev/pEpEngine/test\" endif diff --git a/src/Makefile b/src/Makefile index 850134e..1efb480 100644 --- a/src/Makefile +++ b/src/Makefile @@ -15,7 +15,8 @@ ifneq ($(MAKECMDGOALS),clean) -include $(DEPENDS) endif -.PHONY: install uninstall clean +.PHONY: all install uninstall clean +.DEFAULT_GOAL := all all: $(TARGET) diff --git a/test/Makefile b/test/Makefile index 62e81de..1c77eae 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,30 +1,41 @@ include ../Makefile.conf -LDFLAGS=-L../src $(ENGINE_LIB) +LDFLAGS:=-L../src $(LDFLAGS) LDLIBS=-lstdc++ -lpEpEngine -lpEpAdapter CXXFLAGS:=-I../src -DENGINE_TEST=$(ENGINE_TEST) $(CXXFLAGS) +# Test SRC_TEST=$(wildcard test_*.cc) BIN_TEST=$(subst .cc,,$(SRC_TEST)) +# Framework SRC_FRAMEWORK=$(wildcard framework/*.cc) OBJ_FRAMEWORK=$(subst .cc,.o,$(SRC_FRAMEWORK)) +# Depends +DEP_TEST=$(subst .cc,.d,$(SRC_TEST)) +DEP_FRAMEWORK=$(subst .cc,.d,$(SRC_FRAMEWORK)) +DEPENDS+= $(DEP_TEST) $(DEP_FRAMEWORK) +CXXFLAGS+= -MMD -MP + +ifneq ($(MAKECMDGOALS),clean) + -include $(DEPENDS) +endif + .PHONY: all clean rmtestdata +.DEFAULT_GOAL := all all: $(BIN_TEST) - $(BIN_TEST): $(OBJ_FRAMEWORK) - clean: rm -f $(BIN_TEST) rm -f $(OBJ_FRAMEWORK) rm -Rf *.dSYM + rm -f *.d rm -f *.o rm -Rf /tmp/test_pEp.* rmtestdata: rm -Rf /tmp/test_pEp.* - From 04b86758fa0b7bb4e5542444926084c53ba46680 Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 9 Apr 2021 00:10:57 +0200 Subject: [PATCH 10/24] Tests: framework.hh - no using directives in headers.... --- test/framework/framework.hh | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/test/framework/framework.hh b/test/framework/framework.hh index 6052cec..1bc3a37 100644 --- a/test/framework/framework.hh +++ b/test/framework/framework.hh @@ -10,20 +10,18 @@ #include -using namespace std; - namespace pEp { namespace Test { // manually set up test - void setup(vector &args); + void setup(std::vector &args); // call this in main() for auto set up void setup(int argc = 1, char **argv = nullptr); - void import_key_from_file(string filename); + void import_key_from_file(std::string filename); - using Message = shared_ptr<::message>; - using Identity = shared_ptr<::pEp_identity>; + using Message = std::shared_ptr<::message>; + using Identity = std::shared_ptr<::pEp_identity>; // use this instead of constructor to auto assign ::free_message as // deleter @@ -34,20 +32,20 @@ namespace pEp { Identity make_identity(::pEp_identity *ident); // MIME parser - Message mime_parse(string text); + Message mime_parse(std::string text); // MIME composer - string mime_compose(Message msg); + std::string mime_compose(Message msg); // Sync and Distribution decoder - string make_pEp_msg(Message msg); + std::string make_pEp_msg(Message msg); // wait until Sync has shut down void join_sync_thread(); struct Transport { - string inbox_path = "inbox"; - string outbox_path = "outbox"; + std::string inbox_path = "inbox"; + std::string outbox_path = "outbox"; // reads next message from inbox Message recv(); @@ -57,7 +55,7 @@ namespace pEp { }; extern Transport transport; - extern string path; + extern std::string path; }; // namespace Test }; // namespace pEp From b02fb84ecfa04624143a85ead3779518e08d4459 Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 9 Apr 2021 00:14:06 +0200 Subject: [PATCH 11/24] Tests: lets use namespace pEp, but not more. (Its just a LOT easier to navigate especially for other people, plus the habit of just including every namespace everywhere does not scale, its messy). Use namespace aliases. And lets NOT import a namespace into an other namespace like importing std into Adapter. --- test/framework/framework.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/framework/framework.cc b/test/framework/framework.cc index ffb3e1c..51b1618 100644 --- a/test/framework/framework.cc +++ b/test/framework/framework.cc @@ -21,16 +21,17 @@ #include #include -#include "../src/Adapter.hh" +#include "../../src/Adapter.hh" pEp::Test::Transport pEp::Test::transport; std::string pEp::Test::path; extern std::thread pEp::Adapter::_sync_thread; +using namespace pEp; +using namespace std; + namespace pEp { namespace Test { - using namespace Adapter; - void setup(vector &args) { #ifdef WIN32 @@ -87,7 +88,7 @@ namespace pEp { ::identity_list *il = NULL; cout << key.c_str() << endl; cout << key.length() << endl; - ::PEP_STATUS status = ::import_key(session(), key.c_str(), key.length(), &il); + ::PEP_STATUS status = ::import_key(Adapter::session(), key.c_str(), key.length(), &il); throw_status(status); assert(status == PEP_KEY_IMPORTED); ::free_identity_list(il); @@ -134,7 +135,7 @@ namespace pEp { stringlist_t *keylist; ::PEP_rating rating; ::PEP_decrypt_flags_t flags = 0; - ::PEP_STATUS status = ::decrypt_message(session(), msg.get(), &_dst, &keylist, &rating, &flags); + ::PEP_STATUS status = ::decrypt_message(Adapter::session(), msg.get(), &_dst, &keylist, &rating, &flags); throw_status(status); Message dst; @@ -168,8 +169,9 @@ namespace pEp { void join_sync_thread() { - if (_sync_thread.joinable()) - _sync_thread.join(); + if (Adapter::_sync_thread.joinable()) { + Adapter::_sync_thread.join(); + } } Message Transport::recv() From 0aa66aa54310ffa4e80d7d36ee779eb8fa8269c8 Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 9 Apr 2021 00:19:42 +0200 Subject: [PATCH 12/24] Tests: compiler generated header prerequisites somehow not working --- test/Makefile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/Makefile b/test/Makefile index 1c77eae..759c5cc 100644 --- a/test/Makefile +++ b/test/Makefile @@ -13,14 +13,14 @@ SRC_FRAMEWORK=$(wildcard framework/*.cc) OBJ_FRAMEWORK=$(subst .cc,.o,$(SRC_FRAMEWORK)) # Depends -DEP_TEST=$(subst .cc,.d,$(SRC_TEST)) -DEP_FRAMEWORK=$(subst .cc,.d,$(SRC_FRAMEWORK)) -DEPENDS+= $(DEP_TEST) $(DEP_FRAMEWORK) -CXXFLAGS+= -MMD -MP - -ifneq ($(MAKECMDGOALS),clean) - -include $(DEPENDS) -endif +#DEP_TEST=$(subst .cc,.d,$(SRC_TEST)) +#DEP_FRAMEWORK=$(subst .cc,.d,$(SRC_FRAMEWORK)) +#DEPENDS+=$(DEP_TEST)$(DEP_FRAMEWORK) +#CXXFLAGS+= -MMD -MP +# +#ifneq ($(MAKECMDGOALS),clean) +# -include $(DEPENDS) +#endif .PHONY: all clean rmtestdata .DEFAULT_GOAL := all From c8590750c83385aba2fd397e3f4cb775a3ecee62 Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 9 Apr 2021 00:20:22 +0200 Subject: [PATCH 13/24] Tests: Framework - Add utils.cc with some *_to_string() funcs --- test/framework/utils.cc | 126 ++++++++++++++++++++++++++++++++++++++++ test/framework/utils.hh | 21 +++++++ 2 files changed, 147 insertions(+) create mode 100644 test/framework/utils.cc create mode 100644 test/framework/utils.hh diff --git a/test/framework/utils.cc b/test/framework/utils.cc new file mode 100644 index 0000000..96e2958 --- /dev/null +++ b/test/framework/utils.cc @@ -0,0 +1,126 @@ +// This file is under GNU General Public License 3.0 +// see LICENSE.txt + +#include "utils.hh" + +#include + +#include "../../src/Adapter.hh" +#include "../../src/adapter_group.h" + +using namespace std; +using namespace pEp; + +namespace pEp { + namespace Test { + 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(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(); + } + + + 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 diff --git a/test/framework/utils.hh b/test/framework/utils.hh new file mode 100644 index 0000000..c696e5d --- /dev/null +++ b/test/framework/utils.hh @@ -0,0 +1,21 @@ +// This file is under GNU General Public License 3.0 +// see LICENSE.txt + +#ifndef LIBPEPADAPTER_UTILS_HH +#define LIBPEPADAPTER_UTILS_HH + +#include +#include +#include + +namespace pEp { + namespace Test { + namespace Utils { + std::string identity_to_string(::pEp_identity* ident, 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 \ No newline at end of file From 5555066c4b9288cfe523218040c648e897c4a6c9 Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 9 Apr 2021 00:20:56 +0200 Subject: [PATCH 14/24] Tests: add test_group.cc --- test/test_group.cc | 95 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 test/test_group.cc diff --git a/test/test_group.cc b/test/test_group.cc new file mode 100644 index 0000000..5d0f682 --- /dev/null +++ b/test/test_group.cc @@ -0,0 +1,95 @@ +// This file is under GNU General Public License 3.0 +// see LICENSE.txt + +#include "framework/framework.hh" +#include "framework/utils.hh" + +#include + +//#include + +#include "../src/Adapter.hh" +#include "../src/adapter_group.h" + +using namespace std; +using namespace pEp; + +::PEP_STATUS test_messageToSend(::message* _msg) +{ + pEpLog("called"); + 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) +{ + pEpLog("called"); + 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; +} + +int main(int argc, char** argv) +{ + Test::setup(argc, argv); +// Adapter::pEpLog::set_enabled(true); + bool debug_info_full = true; + + ::pEp_identity* alice = nullptr; + ::pEp_identity* bob = nullptr; + ::pEp_identity* carol = nullptr; + { + pEpLog("creating identity Alice"); + alice = ::new_identity("alice@peptest.ch", NULL, "23", "Alice"); + assert(alice); + alice->lang[0] = 'e'; + alice->lang[1] = 'n'; + ::PEP_STATUS status = ::myself(Adapter::session(), alice); + cout << "Alice:" << Test::Utils::identity_to_string(alice, debug_info_full) << endl; + } + { + pEpLog("creating identity Bob"); + bob = ::new_identity("bob@peptest.ch", NULL, "42", "Bob"); + assert(bob); + bob->lang[0] = 'c'; + bob->lang[1] = 'r'; + ::PEP_STATUS status = ::myself(Adapter::session(), bob); + cout << "Bob:" << Test::Utils::identity_to_string(bob, debug_info_full) << endl; + } + { + pEpLog("creating identity Carol"); + carol = ::new_identity("carol@peptest.ch", NULL, "42", "Carol"); + assert(carol); + carol->lang[0] = 'f'; + carol->lang[1] = 'n'; + ::PEP_STATUS status = ::myself(Adapter::session(), carol); + cout << "Carol:" << Test::Utils::identity_to_string(carol, debug_info_full) << endl; + } + { + Adapter::sync_initialize( + Adapter::SyncModes::Async, + &test_messageToSend, + &test_notifyHandshake, + false); + } + { + ::pEp_group* pep_grp1 = nullptr; + ::pEp_member* mb_bob = ::new_member(bob); + ::pEp_member* mb_carol = ::new_member(carol); + cout << "MEMBER: " << endl + << Test::Utils::member_to_string(mb_carol, debug_info_full) << endl; + + ::member_list* mbl = ::new_memberlist(mb_bob); + ::memberlist_add(mbl, mb_carol); + cout << "MBL: " << Test::Utils::memberlist_to_string(mbl, debug_info_full) << endl; + + ::pEp_identity* grp_ident = ::new_identity("group1@peptest.ch", NULL, "12", "group1"); + ::PEP_STATUS status = ::adapter_group_create(Adapter::session(), grp_ident, alice, mbl, &pep_grp1); + // cout << "GRP: " << group_to_string(pep_grp1, debug_info_full) << endl; + } + + Adapter::shutdown(); + return 0; +} From 706e2d343d82e3399d9664fb0ff96929ec79f6a9 Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 9 Apr 2021 00:26:14 +0200 Subject: [PATCH 15/24] .gitignore --- .gitignore | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 2abfab1..aa7d5bc 100644 --- a/.gitignore +++ b/.gitignore @@ -15,25 +15,12 @@ build/ build-windows/Debug/ build-windows/Release/ build-windows/libpEpAdapter.vcxproj.user -/test/test_adapter.dSYM/Contents/Info.plist -/test/test_adapter_cxx.dSYM/Contents/Info.plist -/test/test_ensure_passphrase.dSYM/Contents/Info.plist -/test/test_leave_device_group.dSYM/Contents/Info.plist -/test/test_library.dSYM/Contents/Info.plist -/test/test_message_cache.dSYM/Contents/Info.plist -/test/test_passphrase_cache.dSYM/Contents/Info.plist -/test/test_semaphore.dSYM/Contents/Info.plist -/test/test_adapter_cxx.dSYM/Contents/Resources/DWARF/test_adapter_cxx -/test/test_adapter_cxx -/test/test_ensure_passphrase.dSYM/Contents/Resources/DWARF/test_ensure_passphrase -/test/test_ensure_passphrase -/test/test_leave_device_group.dSYM/Contents/Resources/DWARF/test_leave_device_group -/test/test_leave_device_group -/test/test_library.dSYM/Contents/Resources/DWARF/test_library -/test/test_library -/test/test_message_cache.dSYM/Contents/Resources/DWARF/test_message_cache -/test/test_message_cache -/test/test_passphrase_cache.dSYM/Contents/Resources/DWARF/test_passphrase_cache -/test/test_passphrase_cache -/test/test_semaphore.dSYM/Contents/Resources/DWARF/test_semaphore -/test/test_semaphore +*.dSYM +test_group +test_adapter_cxx +test_ensure_passphrase +test_leave_device_group +test_library +test_message_cache +test_passphrase_cache +test_semaphore From 030164dbe22fdf88fe9591c644e2627d5366e19b Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 9 Apr 2021 20:37:24 +0200 Subject: [PATCH 16/24] LIB-11: Update adapter_group.h from engine group.h --- src/adapter_group.cc | 68 ++++++++++++++++---------------------------- src/adapter_group.h | 26 ++++++++++------- 2 files changed, 40 insertions(+), 54 deletions(-) diff --git a/src/adapter_group.cc b/src/adapter_group.cc index 572704c..3e5e530 100644 --- a/src/adapter_group.cc +++ b/src/adapter_group.cc @@ -12,58 +12,48 @@ extern "C" { *************************************************************************************************/ DYNAMIC_API PEP_STATUS adapter_group_create( - PEP_SESSION session, - pEp_identity *group_identity, - pEp_identity *manager, - member_list *memberlist, - pEp_group **group -) + PEP_SESSION session, + pEp_identity *group_identity, + pEp_identity *manager, + identity_list *memberlist, + pEp_group **group) { 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 -) +DYNAMIC_API PEP_STATUS +adapter_group_join(PEP_SESSION session, pEp_identity *group_identity, pEp_identity *as_member) { 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 -) +DYNAMIC_API PEP_STATUS +adapter_group_dissolve(PEP_SESSION session, pEp_identity *group_identity, pEp_identity *manager) { 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 -) + PEP_SESSION session, + pEp_identity *group_identity, + pEp_identity *group_member) { 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 -) + PEP_SESSION session, + pEp_identity *group_identity, + pEp_identity *group_member) { 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 -) + PEP_SESSION session, + pEp_identity *group_identity, + pEp_identity *manager, + PEP_rating *rating) { return ::group_rating(session, group_identity, manager, rating); } @@ -73,28 +63,19 @@ DYNAMIC_API PEP_STATUS adapter_group_rating( *************************************************************************************************/ -DYNAMIC_API PEP_STATUS group_query_groups( - PEP_SESSION session, - identity_list **groups -) +DYNAMIC_API PEP_STATUS group_query_groups(PEP_SESSION session, identity_list **groups) { return PEP_STATUS_OK; } -DYNAMIC_API PEP_STATUS group_query_manager( - PEP_SESSION session, - const pEp_identity *const group, - pEp_identity **manager -) +DYNAMIC_API PEP_STATUS +group_query_manager(PEP_SESSION session, const pEp_identity *const group, pEp_identity **manager) { return PEP_STATUS_OK; } -DYNAMIC_API PEP_STATUS group_query_members( - PEP_SESSION session, - const pEp_identity *const group, - identity_list **members -) +DYNAMIC_API PEP_STATUS +group_query_members(PEP_SESSION session, const pEp_identity *const group, identity_list **members) { return PEP_STATUS_OK; } @@ -102,4 +83,3 @@ DYNAMIC_API PEP_STATUS group_query_members( #ifdef __cplusplus } #endif - diff --git a/src/adapter_group.h b/src/adapter_group.h index 67919b7..b3fe44d 100644 --- a/src/adapter_group.h +++ b/src/adapter_group.h @@ -31,12 +31,12 @@ extern "C" { * The manager * * @param[in] session associated session object - * @param[in] group_identity the pEp_identity object representing the group. Must contain at least + * @param[in,out] 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 + * @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] memberlist list of group members + * @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) @@ -44,19 +44,25 @@ extern "C" { * @retval PEP_STATUS_OK on success * error on failure * - * @ownership FIXME + * @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. * - * TODO: member_list *memberlist -> change to identity_list + * @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, - member_list *memberlist, - pEp_group **group + PEP_SESSION session, + pEp_identity *group_identity, + pEp_identity *manager, + identity_list *memberlist, + pEp_group **group ); + /** * * From 1de257538d450e6c1872472b526f7de830424cdf Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 9 Apr 2021 20:37:52 +0200 Subject: [PATCH 17/24] Tests: Framework - add identitylist_to_string() --- test/framework/utils.cc | 20 +++++++++++++++++++- test/framework/utils.hh | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/test/framework/utils.cc b/test/framework/utils.cc index 96e2958..49a4d63 100644 --- a/test/framework/utils.cc +++ b/test/framework/utils.cc @@ -3,7 +3,7 @@ #include "utils.hh" -#include +#include #include "../../src/Adapter.hh" #include "../../src/adapter_group.h" @@ -58,6 +58,24 @@ namespace pEp { 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) { diff --git a/test/framework/utils.hh b/test/framework/utils.hh index c696e5d..3fe514e 100644 --- a/test/framework/utils.hh +++ b/test/framework/utils.hh @@ -6,12 +6,14 @@ #include #include +#include #include namespace pEp { namespace Test { 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); From 805c28a92fbb4c381b5e42b1cca8a4bdb8987d19 Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 9 Apr 2021 20:38:15 +0200 Subject: [PATCH 18/24] LIB-11: update test --- test/test_group.cc | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/test/test_group.cc b/test/test_group.cc index 5d0f682..1844470 100644 --- a/test/test_group.cc +++ b/test/test_group.cc @@ -6,8 +6,6 @@ #include -//#include - #include "../src/Adapter.hh" #include "../src/adapter_group.h" @@ -34,19 +32,20 @@ using namespace pEp; int main(int argc, char** argv) { Test::setup(argc, argv); -// Adapter::pEpLog::set_enabled(true); + // Adapter::pEpLog::set_enabled(true); bool debug_info_full = true; ::pEp_identity* alice = nullptr; ::pEp_identity* bob = nullptr; ::pEp_identity* carol = nullptr; + ::PEP_STATUS status; { pEpLog("creating identity Alice"); alice = ::new_identity("alice@peptest.ch", NULL, "23", "Alice"); assert(alice); alice->lang[0] = 'e'; alice->lang[1] = 'n'; - ::PEP_STATUS status = ::myself(Adapter::session(), alice); + status = ::myself(Adapter::session(), alice); cout << "Alice:" << Test::Utils::identity_to_string(alice, debug_info_full) << endl; } { @@ -55,7 +54,8 @@ int main(int argc, char** argv) assert(bob); bob->lang[0] = 'c'; bob->lang[1] = 'r'; - ::PEP_STATUS status = ::myself(Adapter::session(), bob); + status = ::myself(Adapter::session(), bob); + assert(!status); cout << "Bob:" << Test::Utils::identity_to_string(bob, debug_info_full) << endl; } { @@ -64,7 +64,8 @@ int main(int argc, char** argv) assert(carol); carol->lang[0] = 'f'; carol->lang[1] = 'n'; - ::PEP_STATUS status = ::myself(Adapter::session(), carol); + status = ::myself(Adapter::session(), carol); + assert(!status); cout << "Carol:" << Test::Utils::identity_to_string(carol, debug_info_full) << endl; } { @@ -81,13 +82,18 @@ int main(int argc, char** argv) cout << "MEMBER: " << endl << Test::Utils::member_to_string(mb_carol, debug_info_full) << endl; - ::member_list* mbl = ::new_memberlist(mb_bob); - ::memberlist_add(mbl, mb_carol); - cout << "MBL: " << Test::Utils::memberlist_to_string(mbl, debug_info_full) << endl; + ::identity_list* idl = new_identity_list(bob); + ::identity_list_add(idl, carol); + cout << "IDL: " << Test::Utils::identitylist_to_string(idl, debug_info_full) << endl; ::pEp_identity* grp_ident = ::new_identity("group1@peptest.ch", NULL, "12", "group1"); - ::PEP_STATUS status = ::adapter_group_create(Adapter::session(), grp_ident, alice, mbl, &pep_grp1); - // cout << "GRP: " << group_to_string(pep_grp1, debug_info_full) << endl; + assert(grp_ident); + status = ::myself(Adapter::session(), grp_ident); + assert(!status); + cout << "grp_ident:" << Test::Utils::identity_to_string(grp_ident, debug_info_full) << endl; + ::PEP_STATUS status = ::adapter_group_create(Adapter::session(), grp_ident, alice, idl, &pep_grp1); + assert(!status); + cout << "GRP: " << Test::Utils::group_to_string(pep_grp1, debug_info_full) << endl; } Adapter::shutdown(); From 5df8a83544368b0aa7890d591c1441ff065ac5a7 Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 9 Apr 2021 21:15:37 +0200 Subject: [PATCH 19/24] LIB-11: update test (memberlist of create_group() can only have NON-OWN identities) --- test/test_group.cc | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/test/test_group.cc b/test/test_group.cc index 1844470..3d34509 100644 --- a/test/test_group.cc +++ b/test/test_group.cc @@ -8,6 +8,7 @@ #include "../src/Adapter.hh" #include "../src/adapter_group.h" +#include "../src/status_to_string.hh" using namespace std; using namespace pEp; @@ -40,7 +41,7 @@ int main(int argc, char** argv) ::pEp_identity* carol = nullptr; ::PEP_STATUS status; { - pEpLog("creating identity Alice"); + pEpLog("======== Alice myself()"); alice = ::new_identity("alice@peptest.ch", NULL, "23", "Alice"); assert(alice); alice->lang[0] = 'e'; @@ -49,26 +50,29 @@ int main(int argc, char** argv) cout << "Alice:" << Test::Utils::identity_to_string(alice, debug_info_full) << endl; } { - pEpLog("creating identity Bob"); - bob = ::new_identity("bob@peptest.ch", NULL, "42", "Bob"); + pEpLog("======== Bob update_identity()"); + bob = ::new_identity("bob@peptest.ch", NULL, PEP_OWN_USERID, "Bob"); assert(bob); bob->lang[0] = 'c'; bob->lang[1] = 'r'; - status = ::myself(Adapter::session(), bob); +// status = ::myself(Adapter::session(), bob); + status = ::update_identity(Adapter::session(),bob); assert(!status); cout << "Bob:" << Test::Utils::identity_to_string(bob, debug_info_full) << endl; } { - pEpLog("creating identity Carol"); - carol = ::new_identity("carol@peptest.ch", NULL, "42", "Carol"); + pEpLog("======== Carol update_identity()"); + carol = ::new_identity("carol@peptest.ch", NULL, PEP_OWN_USERID, "Carol"); assert(carol); carol->lang[0] = 'f'; carol->lang[1] = 'n'; - status = ::myself(Adapter::session(), carol); +// status = ::myself(Adapter::session(), carol); + status = ::update_identity(Adapter::session(),carol); assert(!status); cout << "Carol:" << Test::Utils::identity_to_string(carol, debug_info_full) << endl; } { + pEpLog("======== sync_initialize()"); Adapter::sync_initialize( Adapter::SyncModes::Async, &test_messageToSend, @@ -76,26 +80,27 @@ int main(int argc, char** argv) false); } { + pEpLog("======== adapter_group_create()"); ::pEp_group* pep_grp1 = nullptr; - ::pEp_member* mb_bob = ::new_member(bob); - ::pEp_member* mb_carol = ::new_member(carol); - cout << "MEMBER: " << endl - << Test::Utils::member_to_string(mb_carol, debug_info_full) << endl; + // Members ::identity_list* idl = new_identity_list(bob); ::identity_list_add(idl, carol); cout << "IDL: " << Test::Utils::identitylist_to_string(idl, debug_info_full) << endl; - ::pEp_identity* grp_ident = ::new_identity("group1@peptest.ch", NULL, "12", "group1"); + ::pEp_identity* grp_ident = ::new_identity("group1@peptest.ch", NULL, "432", "group1"); assert(grp_ident); status = ::myself(Adapter::session(), grp_ident); assert(!status); cout << "grp_ident:" << Test::Utils::identity_to_string(grp_ident, debug_info_full) << endl; ::PEP_STATUS status = ::adapter_group_create(Adapter::session(), grp_ident, alice, idl, &pep_grp1); + cout << status_to_string(status) << endl; assert(!status); + assert(pep_grp1); cout << "GRP: " << Test::Utils::group_to_string(pep_grp1, debug_info_full) << endl; } + Adapter::shutdown(); return 0; } From dc8d340190bab159150ee6dae15dc0b0c8c68191 Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 9 Apr 2021 22:34:22 +0200 Subject: [PATCH 20/24] adapter_group.cc - pEpLog() every function call --- src/adapter_group.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/adapter_group.cc b/src/adapter_group.cc index 3e5e530..6b7b475 100644 --- a/src/adapter_group.cc +++ b/src/adapter_group.cc @@ -1,7 +1,9 @@ // This file is under GNU General Public License 3.0 // see LICENSE.txt #include + #include "adapter_group.h" +#include "pEpLog.hh" #ifdef __cplusplus extern "C" { @@ -18,18 +20,21 @@ DYNAMIC_API PEP_STATUS adapter_group_create( 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); } @@ -38,6 +43,7 @@ DYNAMIC_API PEP_STATUS adapter_group_invite_member( pEp_identity *group_identity, pEp_identity *group_member) { + pEpLog("called"); return ::group_invite_member(session, group_identity, group_member); } @@ -46,6 +52,7 @@ PEP_STATUS adapter_group_remove_member( pEp_identity *group_identity, pEp_identity *group_member) { + pEpLog("called"); return ::group_remove_member(session, group_identity, group_member); } @@ -55,6 +62,7 @@ DYNAMIC_API PEP_STATUS adapter_group_rating( pEp_identity *manager, PEP_rating *rating) { + pEpLog("called"); return ::group_rating(session, group_identity, manager, rating); } @@ -65,18 +73,21 @@ DYNAMIC_API PEP_STATUS adapter_group_rating( 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; } From 18d61b9f061d3317d1de0d03f93237e5b900f517 Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 9 Apr 2021 22:35:18 +0200 Subject: [PATCH 21/24] LIB-11: Test - add group_rating() / Failing / create / functions for Test Units --- test/test_group.cc | 219 +++++++++++++++++++++++++++++++-------------- 1 file changed, 150 insertions(+), 69 deletions(-) diff --git a/test/test_group.cc b/test/test_group.cc index 3d34509..352bb52 100644 --- a/test/test_group.cc +++ b/test/test_group.cc @@ -13,16 +13,54 @@ using namespace std; using namespace pEp; +/* + * 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. Disssolve + * - 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 + */ + + +bool debug_info_full = true; +::pEp_identity* alice = nullptr; +::pEp_identity* bob = nullptr; +::pEp_identity* carol = nullptr; +::PEP_STATUS status; + +/* + * Callbacks + */ + ::PEP_STATUS test_messageToSend(::message* _msg) { - pEpLog("called"); + 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) { - pEpLog("called"); + 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; @@ -30,76 +68,119 @@ using namespace pEp; return PEP_STATUS_OK; } +/* + * Test Units + */ + +void create_alice_me() +{ + cout << "======== Alice myself()" << endl; + 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 create_bob_partner() +{ + cout << "======== Bob update_identity()" << endl; + 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 create_carol_partner() +{ + cout << "======== Carol update_identity()" << endl; + 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 setup_and_start_sync() +{ + cout << "======== sync_initialize()" << endl; + Adapter::sync_initialize(Adapter::SyncModes::Async, &test_messageToSend, &test_notifyHandshake, false); +} + +void group_rating() +{ + cout << "======== 5. Rating" << endl; + // recreate group identity + ::pEp_identity* grp_ident = ::new_identity("group1@peptest.ch", NULL, NULL, NULL); + assert(grp_ident); + status = ::update_identity(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; + + // 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; + cout << "Rating: " << rating << endl; + assert(!status); +} + +void create_group() +{ + cout << "======== 1. Create group" << endl; + ::pEp_group* pep_grp1 = nullptr; + + // Initial Memberlist + ::identity_list* idl = new_identity_list(bob); + ::identity_list_add(idl, carol); + cout << "IDL: " << Test::Utils::identitylist_to_string(idl, debug_info_full) << endl; + + // Group Identity + ::pEp_identity* 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; + + // Create group + cout << "adapter_group_create()" << endl; + 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; +} + + +/* + * Test Procedure + * It has the advantage that you can comment out one line if a test fails + */ + int main(int argc, char** argv) { Test::setup(argc, argv); - // Adapter::pEpLog::set_enabled(true); - bool debug_info_full = true; - - ::pEp_identity* alice = nullptr; - ::pEp_identity* bob = nullptr; - ::pEp_identity* carol = nullptr; - ::PEP_STATUS status; - { - pEpLog("======== Alice myself()"); - 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 << "Alice:" << Test::Utils::identity_to_string(alice, debug_info_full) << endl; - } - { - pEpLog("======== Bob update_identity()"); - bob = ::new_identity("bob@peptest.ch", NULL, PEP_OWN_USERID, "Bob"); - assert(bob); - bob->lang[0] = 'c'; - bob->lang[1] = 'r'; -// status = ::myself(Adapter::session(), bob); - status = ::update_identity(Adapter::session(),bob); - assert(!status); - cout << "Bob:" << Test::Utils::identity_to_string(bob, debug_info_full) << endl; - } - { - pEpLog("======== Carol update_identity()"); - carol = ::new_identity("carol@peptest.ch", NULL, PEP_OWN_USERID, "Carol"); - assert(carol); - carol->lang[0] = 'f'; - carol->lang[1] = 'n'; -// status = ::myself(Adapter::session(), carol); - status = ::update_identity(Adapter::session(),carol); - assert(!status); - cout << "Carol:" << Test::Utils::identity_to_string(carol, debug_info_full) << endl; - } - { - pEpLog("======== sync_initialize()"); - Adapter::sync_initialize( - Adapter::SyncModes::Async, - &test_messageToSend, - &test_notifyHandshake, - false); - } - { - pEpLog("======== adapter_group_create()"); - ::pEp_group* pep_grp1 = nullptr; - - // Members - ::identity_list* idl = new_identity_list(bob); - ::identity_list_add(idl, carol); - cout << "IDL: " << Test::Utils::identitylist_to_string(idl, debug_info_full) << endl; - - ::pEp_identity* grp_ident = ::new_identity("group1@peptest.ch", NULL, "432", "group1"); - assert(grp_ident); - status = ::myself(Adapter::session(), grp_ident); - assert(!status); - cout << "grp_ident:" << Test::Utils::identity_to_string(grp_ident, debug_info_full) << endl; - ::PEP_STATUS status = ::adapter_group_create(Adapter::session(), grp_ident, alice, idl, &pep_grp1); - cout << status_to_string(status) << endl; - assert(!status); - assert(pep_grp1); - cout << "GRP: " << Test::Utils::group_to_string(pep_grp1, debug_info_full) << endl; - } - + Adapter::pEpLog::set_enabled(false); + debug_info_full = false; + create_alice_me(); + create_bob_partner(); + create_carol_partner(); + setup_and_start_sync(); + create_group(); +// group_rating(); // Failing Adapter::shutdown(); return 0; From d79fb50070992bac0191886c76d6ff86d8242d5f Mon Sep 17 00:00:00 2001 From: heck Date: Sat, 10 Apr 2021 00:24:06 +0200 Subject: [PATCH 22/24] Tests: Framework - Add funcs logH1 / logH2 --- test/framework/utils.cc | 23 ++++++++++++++++++++++- test/framework/utils.hh | 4 ++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/test/framework/utils.cc b/test/framework/utils.cc index 49a4d63..c9df5e7 100644 --- a/test/framework/utils.cc +++ b/test/framework/utils.cc @@ -3,6 +3,8 @@ #include "utils.hh" +#include + #include #include "../../src/Adapter.hh" @@ -13,6 +15,25 @@ 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) { @@ -65,7 +86,7 @@ namespace pEp { builder << endl; builder << std::string(indent, '\t') << "[" << endl; indent++; - for (::identity_list * curr = idl; curr != nullptr; curr = curr->next) { + for (::identity_list* curr = idl; curr != nullptr; curr = curr->next) { builder << identity_to_string(curr->ident, full, indent) << endl; } indent--; diff --git a/test/framework/utils.hh b/test/framework/utils.hh index 3fe514e..ccbc7a9 100644 --- a/test/framework/utils.hh +++ b/test/framework/utils.hh @@ -11,6 +11,10 @@ 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); From c28ecc5764c816ce111fedaddea6ad44003f9262 Mon Sep 17 00:00:00 2001 From: heck Date: Sat, 10 Apr 2021 00:24:34 +0200 Subject: [PATCH 23/24] LIB11: Test - update --- test/test_group.cc | 178 +++++++++++++++++++++++++++------------------ 1 file changed, 106 insertions(+), 72 deletions(-) diff --git a/test/test_group.cc b/test/test_group.cc index 352bb52..b9bc917 100644 --- a/test/test_group.cc +++ b/test/test_group.cc @@ -12,39 +12,13 @@ using namespace std; using namespace pEp; - -/* - * 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. Disssolve - * - 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 - */ - +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; /* @@ -72,9 +46,9 @@ bool debug_info_full = true; * Test Units */ -void create_alice_me() +void test_create_alice_me() { - cout << "======== Alice myself()" << endl; + logH2("test_create_alice_me"); alice = ::new_identity("alice@peptest.ch", NULL, "23", "Alice"); assert(alice); alice->lang[0] = 'e'; @@ -85,9 +59,9 @@ void create_alice_me() cout << "Alice:" << Test::Utils::identity_to_string(alice, debug_info_full) << endl; } -void create_bob_partner() +void test_create_bob_partner() { - cout << "======== Bob update_identity()" << endl; + logH2("test_create_bob_partner"); bob = ::new_identity("bob@peptest.ch", NULL, PEP_OWN_USERID, "Bob"); assert(bob); bob->lang[0] = 'c'; @@ -98,9 +72,9 @@ void create_bob_partner() cout << "Bob:" << Test::Utils::identity_to_string(bob, debug_info_full) << endl; } -void create_carol_partner() +void test_create_carol_partner() { - cout << "======== Carol update_identity()" << endl; + logH2("test_create_carol_partner"); carol = ::new_identity("carol@peptest.ch", NULL, PEP_OWN_USERID, "Carol"); assert(carol); carol->lang[0] = 'f'; @@ -111,76 +85,136 @@ void create_carol_partner() cout << "Carol:" << Test::Utils::identity_to_string(carol, debug_info_full) << endl; } -void setup_and_start_sync() +void test_setup_and_start_sync() { - cout << "======== sync_initialize()" << endl; + logH2("test_setup_and_start_sync"); Adapter::sync_initialize(Adapter::SyncModes::Async, &test_messageToSend, &test_notifyHandshake, false); } -void group_rating() +void test_group_create(::identity_list* idl) { - cout << "======== 5. Rating" << endl; - // recreate group identity - ::pEp_identity* grp_ident = ::new_identity("group1@peptest.ch", NULL, NULL, NULL); + 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 = ::update_identity(Adapter::session(), 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; - // Rating - ::PEP_rating* rating = nullptr; - cout << "adapter_group_rating()" << endl; - status = ::group_rating(Adapter::session(), grp_ident, alice, rating); + 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; - cout << "Rating: " << rating << endl; assert(!status); + assert(pep_grp1); + cout << "GRP: " << Test::Utils::group_to_string(pep_grp1, debug_info_full) << endl; } -void create_group() +void test_group_invite_member(::pEp_identity* ident) { - cout << "======== 1. Create group" << endl; - ::pEp_group* pep_grp1 = nullptr; + logH2("test_group_invite_member"); + status = ::adapter_group_invite_member(Adapter::session(), grp_ident, ident); + cout << "STATUS: " << status_to_string(status) << endl; + assert(!status); +} - // Initial Memberlist - ::identity_list* idl = new_identity_list(bob); - ::identity_list_add(idl, carol); - cout << "IDL: " << Test::Utils::identitylist_to_string(idl, debug_info_full) << endl; +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); +} - // Group Identity - ::pEp_identity* grp_ident = ::new_identity("group1@peptest.ch", NULL, "432", "group1"); - assert(grp_ident); - status = ::myself(Adapter::session(), grp_ident); +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); - cout << "grp_ident:" << Test::Utils::identity_to_string(grp_ident, debug_info_full) << endl; +} - // Create group - cout << "adapter_group_create()" << endl; - status = ::adapter_group_create(Adapter::session(), grp_ident, alice, idl, &pep_grp1); +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); - assert(pep_grp1); - cout << "GRP: " << Test::Utils::group_to_string(pep_grp1, debug_info_full) << endl; + 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); +} /* - * Test Procedure - * It has the advantage that you can comment out one line if a test fails + * 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 = false; - create_alice_me(); - create_bob_partner(); - create_carol_partner(); - setup_and_start_sync(); - create_group(); -// group_rating(); // Failing + 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; From 5e7a46b5ecc9e95cfcb89337fe1bddccf2f2171f Mon Sep 17 00:00:00 2001 From: heck Date: Sat, 10 Apr 2021 00:32:59 +0200 Subject: [PATCH 24/24] LIB11: adapter_group.h - comment out unimplemented query functions --- src/adapter_group.cc | 38 +++++++++++++++++++------------------- src/adapter_group.h | 28 ++++++++++++++-------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/adapter_group.cc b/src/adapter_group.cc index 6b7b475..3c96ff0 100644 --- a/src/adapter_group.cc +++ b/src/adapter_group.cc @@ -71,25 +71,25 @@ DYNAMIC_API PEP_STATUS adapter_group_rating( *************************************************************************************************/ -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; -} +//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 } diff --git a/src/adapter_group.h b/src/adapter_group.h index b3fe44d..e11a046 100644 --- a/src/adapter_group.h +++ b/src/adapter_group.h @@ -219,10 +219,10 @@ DYNAMIC_API PEP_STATUS adapter_group_rating( * */ -DYNAMIC_API PEP_STATUS group_query_groups( - PEP_SESSION session, - identity_list **groups -); +//DYNAMIC_API PEP_STATUS group_query_groups( +// PEP_SESSION session, +// identity_list **groups +//); /** * @@ -240,11 +240,11 @@ DYNAMIC_API PEP_STATUS group_query_groups( * */ -DYNAMIC_API PEP_STATUS group_query_manager( - PEP_SESSION session, - const pEp_identity *const group, - pEp_identity **manager -); +//DYNAMIC_API PEP_STATUS group_query_manager( +// PEP_SESSION session, +// const pEp_identity *const group, +// pEp_identity **manager +//); /** * @@ -262,11 +262,11 @@ DYNAMIC_API PEP_STATUS group_query_manager( * */ -DYNAMIC_API PEP_STATUS group_query_members( - PEP_SESSION session, - const pEp_identity *const group, - identity_list **members -); +//DYNAMIC_API PEP_STATUS group_query_members( +// PEP_SESSION session, +// const pEp_identity *const group, +// identity_list **members +//); #ifdef __cplusplus