diff --git a/test/framework.cc b/test/framework.cc index 486adc3..99cb9b4 100644 --- a/test/framework.cc +++ b/test/framework.cc @@ -20,6 +20,8 @@ #include #include +#include + pEp::Test::Transport pEp::Test::transport; std::string pEp::Test::path; extern std::thread pEp::Adapter::_sync_thread; @@ -81,7 +83,7 @@ namespace pEp { ifstream f(filename, ifstream::in); string key{ istreambuf_iterator(f), istreambuf_iterator() }; ::identity_list *il = NULL; - PEP_STATUS status = ::import_key(session(), key.c_str(), key.length(), &il); + ::PEP_STATUS status = ::import_key(session(), key.c_str(), key.length(), &il); assert(status == PEP_KEY_IMPORTED); ::free_identity_list(il); } @@ -100,7 +102,7 @@ namespace pEp { { ::message *msg; bool has_possible_pEp_msg; - PEP_STATUS status = ::mime_decode_message( + ::PEP_STATUS status = ::mime_decode_message( text.c_str(), text.length(), &msg, @@ -125,9 +127,9 @@ namespace pEp { ::message *_dst; 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_rating rating; + ::PEP_decrypt_flags_t flags = 0; + ::PEP_STATUS status = ::decrypt_message(session(), msg.get(), &_dst, &keylist, &rating, &flags); throw_status(status); Message dst; @@ -140,17 +142,17 @@ namespace pEp { for (auto a = dst.get()->attachments; a && a->value; a = a->next) { if (string("application/pEp.sync") == a->mime_type) { char *_text; - status = PER_to_XER_Sync_msg(a->value, a->size, &_text); + status = ::PER_to_XER_Sync_msg(a->value, a->size, &_text); throw_status(status); text += _text; - pEp_free(_text); + ::pEp_free(_text); return text; } else if (string("application/pEp.distribution") == a->mime_type) { char *_text; - status = PER_to_XER_Distribution_msg(a->value, a->size, &_text); + status = ::PER_to_XER_Distribution_msg(a->value, a->size, &_text); throw_status(status); text += _text; - pEp_free(_text); + ::pEp_free(_text); return text; } } diff --git a/test/framework.hh b/test/framework.hh index 9dfeb59..2f3b97a 100644 --- a/test/framework.hh +++ b/test/framework.hh @@ -7,7 +7,7 @@ #include #include -#include "Adapter.hh" +#include namespace pEp { namespace Test { diff --git a/test/test_adapter.cc b/test/test_adapter.cc index 5629f86..ee0bd5e 100644 --- a/test/test_adapter.cc +++ b/test/test_adapter.cc @@ -6,11 +6,15 @@ #include #include #include + +#include +#include +#include #include -#include "pEpLog.hh" +#include using namespace std; -using namespace pEp::Adapter; +using namespace pEp; PEP_STATUS messageToSend(struct _message *msg) { @@ -18,7 +22,7 @@ PEP_STATUS messageToSend(struct _message *msg) return PEP_STATUS_OK; } -PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal) +PEP_STATUS notifyHandshake(::pEp_identity *me, ::pEp_identity *partner, ::sync_handshake_signal signal) { pEpLog("called()"); return PEP_STATUS_OK; @@ -26,14 +30,14 @@ PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handsha int main(int argc, char **argv) { - pEp::Test::setup(argc, argv); + Test::setup(argc, argv); // Create new identity pEpLog("updating or creating identity for me"); - pEp_identity *me = new_identity("alice@peptest.ch", NULL, "23", "Who the F* is Alice"); + ::pEp_identity *me = new_identity("alice@peptest.ch", NULL, "23", "Who the F* is Alice"); assert(me); - PEP_STATUS status = myself(session(), me); - free_identity(me); + ::PEP_STATUS status = ::myself(Adapter::session(), me); + ::free_identity(me); pEp::throw_status(status); // start and stop sync repeatedly @@ -44,10 +48,10 @@ int main(int argc, char **argv) pEpLog(i); pEpLog("SYNC START"); pEpLog("starting the adapter including sync"); - startup(messageToSend, notifyHandshake); + Adapter::startup(messageToSend, notifyHandshake); pEpLog("SYNC STOP"); usleep(sleepuSec); - shutdown(); + Adapter::shutdown(); } return 0; } diff --git a/test/test_adapter_cxx.cc b/test/test_adapter_cxx.cc index 997acc2..9091abf 100644 --- a/test/test_adapter_cxx.cc +++ b/test/test_adapter_cxx.cc @@ -5,10 +5,14 @@ #include #include #include + #include -#include "pEpLog.hh" +#include +#include + +#include -using namespace pEp::Adapter; +using namespace pEp; PEP_STATUS messageToSend(struct _message *msg) { @@ -16,7 +20,7 @@ PEP_STATUS messageToSend(struct _message *msg) return PEP_STATUS_OK; } -PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal) +PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, ::sync_handshake_signal signal) { pEpLog("called"); return PEP_STATUS_OK; @@ -41,11 +45,11 @@ int main(int argc, char **argv) // Create new identity pEpLog("updating or creating identity for me"); - pEp_identity *me = new_identity("alice@peptest.ch", NULL, "23", "Who the F* is Alice"); + ::pEp_identity *me = ::new_identity("alice@peptest.ch", NULL, "23", "Who the F* is Alice"); assert(me); - PEP_STATUS status = myself(session(), me); - free_identity(me); - pEp::throw_status(status); + ::PEP_STATUS status = ::myself(Adapter::session(), me); + ::free_identity(me); + throw_status(status); // start and stop sync repeatedly useconds_t sleepuSec = 1000 * 100; @@ -55,7 +59,7 @@ int main(int argc, char **argv) pEpLog(i); pEpLog("SYNC START"); pEpLog("starting the adapter including sync"); - startup( + Adapter::startup( messageToSend, notifyHandshake, &o, @@ -63,7 +67,7 @@ int main(int argc, char **argv) &JNISync::onSyncShutdown); pEpLog("SYNC STOP"); usleep(sleepuSec); - shutdown(); + Adapter::shutdown(); } return 0; } diff --git a/test/test_ensure_passphrase.cc b/test/test_ensure_passphrase.cc index 12ef456..d00ea8f 100644 --- a/test/test_ensure_passphrase.cc +++ b/test/test_ensure_passphrase.cc @@ -9,15 +9,15 @@ #include "framework.hh" -#include "passphrase_cache.hh" -#include "status_to_string.hh" +#include +#include +#include #include #include #include using namespace pEp; -using namespace pEp::Adapter; using namespace std; int main(int argc, char** argv) @@ -38,15 +38,15 @@ int main(int argc, char** argv) Test::import_key_from_file(bob_filename); Test::import_key_from_file(erwin_filename); - pEp_identity* bob = ::new_identity("bob@example.org", bob_fpr, "BOB", "Bob Dog"); - PEP_STATUS status = ::set_own_key(session(), bob, bob_fpr); + ::pEp_identity* bob = ::new_identity("bob@example.org", bob_fpr, "BOB", "Bob Dog"); + ::PEP_STATUS status = ::set_own_key(Adapter::session(), bob, bob_fpr); assert(status == PEP_STATUS_OK); - pEp_identity* erwin = ::new_identity("erwin@example.org", erwin_fpr, "BOB", "Bob is Erwin"); - status = ::set_own_key(session(), erwin, erwin_fpr); + ::pEp_identity* erwin = ::new_identity("erwin@example.org", erwin_fpr, "BOB", "Bob is Erwin"); + status = ::set_own_key(Adapter::session(), erwin, erwin_fpr); assert(status == PEP_STATUS_OK); - status = ::key_reset_all_own_keys(session()); + status = ::key_reset_all_own_keys(Adapter::session()); assert(status == PEP_STATUS_OK); ::free_identity(bob); diff --git a/test/test_leave_device_group.cc b/test/test_leave_device_group.cc index 98bf827..2e7fb97 100644 --- a/test/test_leave_device_group.cc +++ b/test/test_leave_device_group.cc @@ -3,14 +3,13 @@ #include #include "framework.hh" -#include "passphrase_cache.hh" -#include "callback_dispatcher.hh" +#include +#include #include -using namespace pEp; -using namespace pEp::Adapter; using namespace std; +using namespace pEp; vector expected_msg = { "synchronizeGroupKeys", "groupKeysUpdate", @@ -24,7 +23,7 @@ vector<::sync_handshake_signal> expected_notification = { SYNC_NOTIFY_IN_GROUP, SYNC_NOTIFY_START, SYNC_NOTIFY_STOP }; -PEP_STATUS test_messageToSend(::message* _msg) +::PEP_STATUS test_messageToSend(::message* _msg) { static auto actual = expected_msg.begin(); @@ -37,7 +36,7 @@ PEP_STATUS test_messageToSend(::message* _msg) } -PEP_STATUS test_notifyHandshake(pEp_identity* _me, pEp_identity* _partner, sync_handshake_signal signal) +::PEP_STATUS test_notifyHandshake(::pEp_identity* _me, ::pEp_identity* _partner, sync_handshake_signal signal) { static auto actual = expected_notification.begin(); @@ -52,7 +51,7 @@ PEP_STATUS test_notifyHandshake(pEp_identity* _me, pEp_identity* _partner, sync_ int main(int argc, char** argv) { Test::setup(argc, argv); - session(); + Adapter::session(); // set up two own identites for sync @@ -71,24 +70,24 @@ int main(int argc, char** argv) Test::Identity bob = Test::make_identity( ::new_identity("bob@example.org", bob_fpr, "BOB", "Bob Dog")); - PEP_STATUS status = ::set_own_key(session(), bob.get(), bob_fpr); + PEP_STATUS status = ::set_own_key(Adapter::session(), bob.get(), bob_fpr); assert(status == PEP_STATUS_OK); - status = ::enable_identity_for_sync(session(), bob.get()); + status = ::enable_identity_for_sync(Adapter::session(), bob.get()); assert(status == PEP_STATUS_OK); Test::Identity erwin = Test::make_identity( ::new_identity("erwin@example.org", erwin_fpr, "BOB", "Bob is Erwin")); - status = ::set_own_key(session(), erwin.get(), erwin_fpr); + status = ::set_own_key(Adapter::session(), erwin.get(), erwin_fpr); assert(status == PEP_STATUS_OK); - status = ::enable_identity_for_sync(session(), erwin.get()); + status = ::enable_identity_for_sync(Adapter::session(), erwin.get()); assert(status == PEP_STATUS_OK); // simulate a device group by setting the identities to in sync - status = set_identity_flags(session(), bob.get(), PEP_idf_devicegroup); - status = set_identity_flags(session(), erwin.get(), PEP_idf_devicegroup); + status = ::set_identity_flags(Adapter::session(), bob.get(), PEP_idf_devicegroup); + status = ::set_identity_flags(Adapter::session(), erwin.get(), PEP_idf_devicegroup); // register at callback_dispatcher and start sync @@ -97,23 +96,24 @@ int main(int argc, char** argv) // leave device group - status = ::leave_device_group(session()); + + status = ::leave_device_group(Adapter::session()); // wait for sync shutdown and release first session Test::join_sync_thread(); - assert(!is_sync_running()); + assert(!Adapter::is_sync_running()); // switch off and on again CallbackDispatcher::start_sync(); sleep(2); - assert(is_sync_running()); + assert(Adapter::is_sync_running()); CallbackDispatcher::stop_sync(); Test::join_sync_thread(); - assert(!is_sync_running()); + assert(!Adapter::is_sync_running()); - session(Adapter::release); + Adapter::session(Adapter::release); return 0; } diff --git a/test/test_library.cc b/test/test_library.cc index 2c43c30..522279a 100644 --- a/test/test_library.cc +++ b/test/test_library.cc @@ -4,10 +4,8 @@ #include #include - using namespace pEp; - // Producer's data: class P { public: diff --git a/test/test_message_cache.cc b/test/test_message_cache.cc index bfab699..e5d1243 100644 --- a/test/test_message_cache.cc +++ b/test/test_message_cache.cc @@ -1,9 +1,10 @@ +#include "framework.hh" #include #include #include #include -#include "message_cache.hh" -#include "framework.hh" +#include +#include using namespace std; using namespace pEp; @@ -12,8 +13,8 @@ int main(int argc, char **argv) { Test::setup(argc, argv); - pEp_identity *alice = ::new_identity("alice@mail.com", nullptr, PEP_OWN_USERID, "Alice"); - ::myself(pEp::Adapter::session(), alice); + ::pEp_identity *alice = ::new_identity("alice@mail.com", nullptr, PEP_OWN_USERID, "Alice"); + ::myself(Adapter::session(), alice); char *mime = strdup("From: Alice \n" "To: Bob \n" @@ -25,25 +26,25 @@ int main(int argc, char **argv) ::message *src = nullptr; bool has_possible_pEp_msg; - PEP_STATUS status = MessageCache::cache_mime_decode_message( + ::PEP_STATUS status = MessageCache::cache_mime_decode_message( mime, strlen(mime), &src, &has_possible_pEp_msg); assert(status == PEP_STATUS_OK); - status = ::myself(pEp::Adapter::session(), src->from); + status = ::myself(Adapter::session(), src->from); assert(status == PEP_STATUS_OK); - ::update_identity(pEp::Adapter::session(), src->to->ident); + ::update_identity(Adapter::session(), src->to->ident); assert(status == PEP_STATUS_OK); - pEp_identity *bob = identity_dup(src->to->ident); + ::pEp_identity *bob = identity_dup(src->to->ident); - src->dir = PEP_dir_outgoing; + src->dir = ::PEP_dir_outgoing; ::message *dst = nullptr; status = MessageCache::cache_encrypt_message( - pEp::Adapter::session(), + Adapter::session(), src, nullptr, &dst, @@ -75,12 +76,12 @@ int main(int argc, char **argv) assert(src->longmsg == nullptr); assert(src->attachments == nullptr); - PEP_rating rating; - PEP_decrypt_flags_t flags = 0; - stringlist_t *keylist = nullptr; + ::PEP_rating rating; + ::PEP_decrypt_flags_t flags = 0; + ::stringlist_t *keylist = nullptr; status = MessageCache::cache_decrypt_message( - pEp::Adapter::session(), + Adapter::session(), src, &dst, &keylist, @@ -108,6 +109,6 @@ int main(int argc, char **argv) ::free_identity(bob); ::free_identity(alice); - pEp::Adapter::session(pEp::Adapter::release); + Adapter::session(Adapter::release); return 0; } diff --git a/test/test_passphrase_cache.cc b/test/test_passphrase_cache.cc index f5246ae..3de8a11 100644 --- a/test/test_passphrase_cache.cc +++ b/test/test_passphrase_cache.cc @@ -1,20 +1,24 @@ +#include "framework.hh" + #include #include #include + #include +#include +#include +#include -#include "framework.hh" -#include "passphrase_cache.hh" -#include "status_to_string.hh" +using namespace pEp; extern "C" { -PEP_STATUS api_test1(PEP_SESSION session, const char *str, char *bytes, int n, ::stringlist_t *sl) +::PEP_STATUS api_test1(::PEP_SESSION session, const char *str, char *bytes, int n, ::stringlist_t *sl) { std::cout << "called api_test1\n"; return PEP_WRONG_PASSPHRASE; } -PEP_STATUS api_test2(PEP_SESSION session, int n, const char *str, char *bytes, ::stringlist_t *sl) +::PEP_STATUS api_test2(::PEP_SESSION session, int n, const char *str, char *bytes, ::stringlist_t *sl) { std::cout << "called api_test2\n"; return PEP_STATUS_OK; @@ -23,14 +27,14 @@ PEP_STATUS api_test2(PEP_SESSION session, int n, const char *str, char *bytes, : int main(int argc, char **argv) { - pEp::Test::setup(argc, argv); + Test::setup(argc, argv); const char *str = "23"; char *bytes = NULL; int n = 42; ::stringlist_t *sl = NULL; - pEp::PassphraseCache cache{ 2, std::chrono::seconds(1) }; + PassphraseCache cache{ 2, std::chrono::seconds(1) }; cache.add("say"); cache.add("hello"); cache.add("world"); @@ -53,21 +57,15 @@ int main(int argc, char **argv) return false; }); - PEP_STATUS status = cache.api( - api_test1, - pEp::Adapter::session(), - "23", - bytes, - n, - (::stringlist_t *)NULL); + ::PEP_STATUS status = cache.api(api_test1, Adapter::session(), "23", bytes, n, (::stringlist_t *)NULL); assert(status == PEP_WRONG_PASSPHRASE); - status = cache.api(api_test2, pEp::Adapter::session(), n, str, bytes, sl); + status = cache.api(api_test2, Adapter::session(), n, str, bytes, sl); assert(status == PEP_STATUS_OK); cache.add("hello"); cache.add("world"); std::cout << "expected: two passphrases in reverse order\n"; - pEp::PassphraseCache _cache = cache; + PassphraseCache _cache = cache; try { while (1) { std::cout << "'" << _cache.latest_passphrase(_cache) << "'\n"; @@ -75,12 +73,12 @@ int main(int argc, char **argv) } catch (std::underflow_error &) { } - pEp::passphrase_cache.add("hello"); - pEp::passphrase_cache.add("world"); + passphrase_cache.add("hello"); + passphrase_cache.add("world"); std::cout << "two times PEP_STATUS_OK (0), one time PEP_WRONG_PASSPHRASE (2561)\n"; do { - status = pEp::PassphraseCache::config_next_passphrase(); - std::cout << pEp::status_to_string(status) << " (" << status << ")\n"; + status = PassphraseCache::config_next_passphrase(); + std::cout << status_to_string(status) << " (" << status << ")\n"; } while (status == PEP_STATUS_OK); sleep(2); @@ -91,11 +89,11 @@ int main(int argc, char **argv) return false; }); - status = cache.api(api_test1, pEp::Adapter::session(), str, bytes, n, sl); + status = cache.api(api_test1, Adapter::session(), str, bytes, n, sl); assert(status == PEP_WRONG_PASSPHRASE); - status = cache.api(api_test2, pEp::Adapter::session(), 23, str, bytes, sl); + status = cache.api(api_test2, Adapter::session(), 23, str, bytes, sl); assert(status == PEP_STATUS_OK); - pEp::Adapter::session(pEp::Adapter::release); + Adapter::session(Adapter::release); return 0; }