Tests: Be ::explicit about global namespace, dont include headers in headers (unnecessarily), be in the namespace pEp, not more

pull/8/head
heck 2 years ago
parent 7cd8f9eaec
commit 9f342cef80

@ -20,6 +20,8 @@
#include <pEp/sync_codec.h>
#include <pEp/distribution_codec.h>
#include <Adapter.hh>
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<char>(f), istreambuf_iterator<char>() };
::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;
}
}

@ -7,7 +7,7 @@
#include <vector>
#include <memory>
#include "Adapter.hh"
#include <pEp/message.h>
namespace pEp {
namespace Test {

@ -6,11 +6,15 @@
#include <assert.h>
#include <unistd.h>
#include <sys/param.h>
#include <pEpLog.hh>
#include <Adapter.hh>
#include <pEp/sync_api.h>
#include <pEp/keymanagement.h>
#include "pEpLog.hh"
#include <pEp/message_api.h>
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;
}

@ -5,10 +5,14 @@
#include <iostream>
#include <assert.h>
#include <unistd.h>
#include <pEp/keymanagement.h>
#include "pEpLog.hh"
#include <pEpLog.hh>
#include <pEp/sync_api.h>
#include <Adapter.hh>
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<JNISync>(
Adapter::startup<JNISync>(
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;
}

@ -9,15 +9,15 @@
#include "framework.hh"
#include "passphrase_cache.hh"
#include "status_to_string.hh"
#include <passphrase_cache.hh>
#include <status_to_string.hh>
#include <Adapter.hh>
#include <pEp/message_api.h>
#include <pEp/keymanagement.h>
#include <pEp/key_reset.h>
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);

@ -3,14 +3,13 @@
#include <unistd.h>
#include "framework.hh"
#include "passphrase_cache.hh"
#include "callback_dispatcher.hh"
#include <passphrase_cache.hh>
#include <callback_dispatcher.hh>
#include <pEp/sync_api.h>
using namespace pEp;
using namespace pEp::Adapter;
using namespace std;
using namespace pEp;
vector<string> 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;
}

@ -4,10 +4,8 @@
#include <iostream>
#include <thread>
using namespace pEp;
// Producer's data:
class P {
public:

@ -1,9 +1,10 @@
#include "framework.hh"
#include <iostream>
#include <cassert>
#include <sys/param.h>
#include <unistd.h>
#include "message_cache.hh"
#include "framework.hh"
#include <message_cache.hh>
#include <Adapter.hh>
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 <alice@mail.com>\n"
"To: Bob <bob@mail.com>\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;
}

@ -1,20 +1,24 @@
#include "framework.hh"
#include <iostream>
#include <unistd.h>
#include <assert.h>
#include <sys/param.h>
#include <passphrase_cache.hh>
#include <status_to_string.hh>
#include <Adapter.hh>
#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;
}

Loading…
Cancel
Save