C++11 library providing functionality common to all adapters.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
4.1 KiB

  1. // This file is under GNU General Public License 3.0
  2. // see LICENSE.txt
  3. #include "framework/framework.hh"
  4. #include "framework/utils.hh"
  5. #include <iostream>
  6. #include "../src/Adapter.hh"
  7. #include "../src/status_to_string.hh"
  8. #include "../src/ListManagerDummy.hh"
  9. using namespace std;
  10. using namespace pEp;
  11. using namespace pEp::Test::Log;
  12. bool debug_info_full = true;
  13. ::pEp_identity* alice = nullptr;
  14. ::pEp_identity* bob = nullptr;
  15. ::pEp_identity* carol = nullptr;
  16. ::pEp_identity* grp_ident = nullptr;
  17. ::PEP_STATUS status;
  18. ListManagerInterface* lm_backend;
  19. /*
  20. * Test Units
  21. */
  22. void test_create_alice_me()
  23. {
  24. logH2("test_create_alice_me");
  25. alice = ::new_identity("alice@peptest.ch", NULL, "23", "Alice");
  26. assert(alice);
  27. alice->lang[0] = 'e';
  28. alice->lang[1] = 'n';
  29. status = ::myself(Adapter::session(), alice);
  30. cout << "STATUS: " << status_to_string(status) << endl;
  31. assert(!status);
  32. cout << "Alice:" << Test::Utils::identity_to_string(alice, debug_info_full) << endl;
  33. }
  34. void test_create_bob_partner()
  35. {
  36. logH2("test_create_bob_partner");
  37. bob = ::new_identity("bob@peptest.ch", NULL, PEP_OWN_USERID, "Bob");
  38. assert(bob);
  39. bob->lang[0] = 'c';
  40. bob->lang[1] = 'r';
  41. status = ::update_identity(Adapter::session(), bob);
  42. cout << "STATUS: " << status_to_string(status) << endl;
  43. assert(!status);
  44. cout << "Bob:" << Test::Utils::identity_to_string(bob, debug_info_full) << endl;
  45. }
  46. void test_create_carol_partner()
  47. {
  48. logH2("test_create_carol_partner");
  49. carol = ::new_identity("carol@peptest.ch", NULL, PEP_OWN_USERID, "Carol");
  50. assert(carol);
  51. carol->lang[0] = 'f';
  52. carol->lang[1] = 'n';
  53. status = ::update_identity(Adapter::session(), carol);
  54. cout << "STATUS: " << status_to_string(status) << endl;
  55. assert(!status);
  56. cout << "Carol:" << Test::Utils::identity_to_string(carol, debug_info_full) << endl;
  57. }
  58. void test_group_create(::identity_list* idl)
  59. {
  60. logH2("test_group_create");
  61. cout << "IDL: " << Test::Utils::identitylist_to_string(idl, debug_info_full) << endl;
  62. cout << "create group identity" << endl;
  63. grp_ident = ::new_identity("group1@peptest.ch", NULL, "432", "group1");
  64. assert(grp_ident);
  65. status = ::myself(Adapter::session(), grp_ident);
  66. cout << "STATUS: " << status_to_string(status) << endl;
  67. assert(!status);
  68. cout << "grp_ident:" << Test::Utils::identity_to_string(grp_ident, debug_info_full) << endl;
  69. lm_backend->create(grp_ident, alice, idl);
  70. }
  71. void test_group_join(::pEp_identity* ident)
  72. {
  73. logH2("test_group_join");
  74. lm_backend->join(grp_ident, ident);
  75. }
  76. void test_group_remove_member(::pEp_identity* ident)
  77. {
  78. logH2("test_group_remove_member");
  79. lm_backend->remove_member(grp_ident, ident);
  80. }
  81. void test_group_dissolve()
  82. {
  83. logH2("test_group_dissolve");
  84. lm_backend->dissolve(grp_ident);
  85. }
  86. /*
  87. * Update functions
  88. * ----------------
  89. * Test procedure:
  90. * 1. Create group
  91. * - group_create(Alice)
  92. * 2. Add Bob
  93. * - group_join(Bob)
  94. * 3. Add Carol
  95. * - group_join(Carol)
  96. * 4. Remove Carol
  97. * - group_remove_member(Carol)
  98. * 6. Dissolve
  99. * - group_dissolve()
  100. *
  101. * Query functions
  102. * ---------------
  103. * Always test all the query functions for correctness between every step above.
  104. * group_query_groups()
  105. * group_query_manager()
  106. * group_query_members
  107. */
  108. int main(int argc, char** argv)
  109. {
  110. Test::setup(argc, argv);
  111. Adapter::pEpLog::set_enabled(true);
  112. debug_info_full = false;
  113. // Setup Test Context
  114. test_create_alice_me();
  115. test_create_bob_partner();
  116. test_create_carol_partner();
  117. // Setup list manager backend
  118. ListManagerDummy lm_dummy{};
  119. lm_backend = &lm_dummy;
  120. logH1("1. Create group");
  121. ::identity_list* initial_memberlist = nullptr;
  122. initial_memberlist = new_identity_list(bob);
  123. ::identity_list_add(initial_memberlist, carol);
  124. test_group_create(initial_memberlist);
  125. logH1("2. Add Bob");
  126. test_group_join(bob); // Fails
  127. logH1("3. Add Carol");
  128. test_group_join(carol);
  129. logH1("4. Remove Carol");
  130. test_group_remove_member(carol);
  131. logH1("6. Dissolve");
  132. test_group_dissolve();
  133. Adapter::shutdown();
  134. return 0;
  135. }