Browse Source

LIB11: Test - update

LIB-12
heck 4 years ago
parent
commit
c28ecc5764
  1. 178
      test/test_group.cc

178
test/test_group.cc

@ -12,39 +12,13 @@
using namespace std; using namespace std;
using namespace pEp; using namespace pEp;
using namespace pEp::Test::Log;
/*
* 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; bool debug_info_full = true;
::pEp_identity* alice = nullptr; ::pEp_identity* alice = nullptr;
::pEp_identity* bob = nullptr; ::pEp_identity* bob = nullptr;
::pEp_identity* carol = nullptr; ::pEp_identity* carol = nullptr;
::pEp_identity* grp_ident = nullptr;
::PEP_STATUS status; ::PEP_STATUS status;
/* /*
@ -72,9 +46,9 @@ bool debug_info_full = true;
* Test Units * 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"); alice = ::new_identity("alice@peptest.ch", NULL, "23", "Alice");
assert(alice); assert(alice);
alice->lang[0] = 'e'; alice->lang[0] = 'e';
@ -85,9 +59,9 @@ void create_alice_me()
cout << "Alice:" << Test::Utils::identity_to_string(alice, debug_info_full) << endl; 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"); bob = ::new_identity("bob@peptest.ch", NULL, PEP_OWN_USERID, "Bob");
assert(bob); assert(bob);
bob->lang[0] = 'c'; bob->lang[0] = 'c';
@ -98,9 +72,9 @@ void create_bob_partner()
cout << "Bob:" << Test::Utils::identity_to_string(bob, debug_info_full) << endl; 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"); carol = ::new_identity("carol@peptest.ch", NULL, PEP_OWN_USERID, "Carol");
assert(carol); assert(carol);
carol->lang[0] = 'f'; carol->lang[0] = 'f';
@ -111,76 +85,136 @@ void create_carol_partner()
cout << "Carol:" << Test::Utils::identity_to_string(carol, debug_info_full) << endl; 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); 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; logH2("test_group_create");
// recreate group identity cout << "IDL: " << Test::Utils::identitylist_to_string(idl, debug_info_full) << endl;
::pEp_identity* grp_ident = ::new_identity("group1@peptest.ch", NULL, NULL, NULL);
cout << "create group identity" << endl;
grp_ident = ::new_identity("group1@peptest.ch", NULL, "432", "group1");
assert(grp_ident); assert(grp_ident);
status = ::update_identity(Adapter::session(), grp_ident); status = ::myself(Adapter::session(), grp_ident);
cout << "STATUS: " << status_to_string(status) << endl; cout << "STATUS: " << status_to_string(status) << endl;
assert(!status); assert(!status);
cout << "grp_ident:" << Test::Utils::identity_to_string(grp_ident, debug_info_full) << endl; cout << "grp_ident:" << Test::Utils::identity_to_string(grp_ident, debug_info_full) << endl;
// Rating cout << "adapter_group_create()" << endl;
::PEP_rating* rating = nullptr; ::pEp_group* pep_grp1 = nullptr;
cout << "adapter_group_rating()" << endl; status = ::adapter_group_create(Adapter::session(), grp_ident, alice, idl, &pep_grp1);
status = ::group_rating(Adapter::session(), grp_ident, alice, rating);
cout << "STATUS: " << status_to_string(status) << endl; cout << "STATUS: " << status_to_string(status) << endl;
cout << "Rating: " << rating << endl;
assert(!status); 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; logH2("test_group_invite_member");
::pEp_group* pep_grp1 = nullptr; status = ::adapter_group_invite_member(Adapter::session(), grp_ident, ident);
cout << "STATUS: " << status_to_string(status) << endl;
assert(!status);
}
// Initial Memberlist void test_group_join(::pEp_identity* ident)
::identity_list* idl = new_identity_list(bob); {
::identity_list_add(idl, carol); logH2("test_group_join");
cout << "IDL: " << Test::Utils::identitylist_to_string(idl, debug_info_full) << endl; status = ::adapter_group_join(Adapter::session(), grp_ident, ident);
cout << "STATUS: " << status_to_string(status) << endl;
assert(!status);
}
// Group Identity void test_group_remove_member(::pEp_identity* ident)
::pEp_identity* grp_ident = ::new_identity("group1@peptest.ch", NULL, "432", "group1"); {
assert(grp_ident); logH2("test_group_remove_member");
status = ::myself(Adapter::session(), grp_ident); status = ::adapter_group_remove_member(Adapter::session(), grp_ident, ident);
cout << "STATUS: " << status_to_string(status) << endl; cout << "STATUS: " << status_to_string(status) << endl;
assert(!status); assert(!status);
cout << "grp_ident:" << Test::Utils::identity_to_string(grp_ident, debug_info_full) << endl; }
// Create group void test_group_rating()
cout << "adapter_group_create()" << endl; {
status = ::adapter_group_create(Adapter::session(), grp_ident, alice, idl, &pep_grp1); 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; cout << "STATUS: " << status_to_string(status) << endl;
assert(!status); assert(!status);
assert(pep_grp1); cout << "Rating: " << rating << endl;
cout << "GRP: " << Test::Utils::group_to_string(pep_grp1, debug_info_full) << 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 * Update functions
* It has the advantage that you can comment out one line if a test fails * ----------------
* 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) int main(int argc, char** argv)
{ {
Test::setup(argc, argv); Test::setup(argc, argv);
Adapter::pEpLog::set_enabled(false); Adapter::pEpLog::set_enabled(false);
debug_info_full = false; debug_info_full = true;
create_alice_me();
create_bob_partner(); // Setup Test Context
create_carol_partner(); test_create_alice_me();
setup_and_start_sync(); test_create_bob_partner();
create_group(); test_create_carol_partner();
// group_rating(); // Failing 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(); Adapter::shutdown();
return 0; return 0;

Loading…
Cancel
Save