Test: API changes update all tests

* call session.initialize() before using a session
* use session.release() instead of session.(release)
* Adapter::startup() arguments moved to session.initialize()
* Adapter::shutdown() renamed to stop_sync()
LIB-11
heck 2 years ago
parent 4a8cbbfd38
commit 64c652652c

@ -9,6 +9,7 @@
#include <pEp/sync_api.h>
#include <pEp/keymanagement.h>
#include "../src/Adapter.hh"
#include "../src/utils.hh"
using namespace std;
using namespace pEp;
@ -28,7 +29,9 @@ PEP_STATUS notifyHandshake(::pEp_identity *me, ::pEp_identity *partner, ::sync_h
int main(int argc, char **argv)
{
Test::setup(argc, argv);
Adapter::pEpLog::set_enabled(true);
Adapter::session.initialize(Adapter::SyncModes::Async, false, messageToSend, notifyHandshake);
// Create new identity
TESTLOG("updating or creating identity for me");
::pEp_identity *me = new_identity("alice@peptest.ch", NULL, "23", "Who the F* is Alice");
@ -45,10 +48,10 @@ int main(int argc, char **argv)
TESTLOG(i);
TESTLOG("SYNC START");
TESTLOG("starting the adapter including sync");
Adapter::startup(messageToSend, notifyHandshake);
Adapter::startup();
TESTLOG("SYNC STOP");
usleep(sleepuSec);
Adapter::shutdown();
Adapter::stop_sync();
}
return 0;
}

@ -16,7 +16,7 @@ using namespace std;
int main(int argc, char** argv)
{
Test::setup(argc, argv);
Adapter::session.initialize();
passphrase_cache.add("erwin");
passphrase_cache.add("cathy");
passphrase_cache.add("bob");

@ -72,7 +72,6 @@ GroupQueryInterface* gq = nullptr;
void test_create_alice_me()
{
// Adapter::session(pEp::Adapter::release);
logH2("test_create_alice_me");
alice = ::new_identity("alice@peptest.ch", NULL, "23", "Alice");
assert(alice);
@ -115,7 +114,7 @@ void test_create_carol_partner()
void test_setup_and_start_sync()
{
logH2("test_setup_and_start_sync");
Adapter::sync_initialize(Adapter::SyncModes::Async, &test_messageToSend, &test_notifyHandshake, false);
Adapter::start_sync();
}
void test_group_create()
@ -220,7 +219,7 @@ int main(int argc, char** argv)
// gu = &gdr;
// gq = &gdr;
Adapter::session.initialize();
// Setup Test Context
test_create_alice_me();
@ -250,6 +249,6 @@ int main(int argc, char** argv)
test_group_dissolve();
Adapter::shutdown();
Adapter::stop_sync();
return 0;
}

@ -9,6 +9,7 @@
#include <pEp/sync_api.h>
#include "../src/callback_dispatcher.hh"
#include "../src/Adapter.hh"
#include "../src/passphrase_cache.hh"
using namespace std;
@ -54,7 +55,7 @@ vector<::sync_handshake_signal> expected_notification = { SYNC_NOTIFY_IN_GROUP,
int main(int argc, char** argv)
{
Test::setup(argc, argv);
Adapter::session();
Adapter::session.initialize(pEp::Adapter::SyncModes::Async, false);
// set up two own identites for sync
@ -95,7 +96,7 @@ int main(int argc, char** argv)
// register at callback_dispatcher and start sync
callback_dispatcher.add(test_messageToSend, test_notifyHandshake);
CallbackDispatcher::start_sync();
Adapter::start_sync();
// leave device group
@ -109,14 +110,14 @@ int main(int argc, char** argv)
// switch off and on again
CallbackDispatcher::start_sync();
Adapter::start_sync();
sleep(2);
assert(Adapter::is_sync_running());
CallbackDispatcher::stop_sync();
Adapter::stop_sync();
Test::join_sync_thread();
assert(!Adapter::is_sync_running());
Adapter::session(Adapter::release);
Adapter::session.release();
return 0;
}

@ -17,6 +17,7 @@ using namespace pEp;
int main(int argc, char **argv)
{
Test::setup(argc, argv);
Adapter::session.initialize();
::pEp_identity *alice = ::new_identity("alice@mail.com", nullptr, PEP_OWN_USERID, "Alice");
::myself(Adapter::session(), alice);
@ -118,6 +119,6 @@ int main(int argc, char **argv)
::free_identity(bob);
::free_identity(alice);
Adapter::session(Adapter::release);
Adapter::session.release();
return 0;
}

@ -30,7 +30,7 @@ extern "C" {
int main(int argc, char **argv)
{
Test::setup(argc, argv);
Adapter::session.initialize();
const char *str = "23";
char *bytes = NULL;
int n = 42;
@ -96,6 +96,6 @@ int main(int argc, char **argv)
status = cache.api(api_test2, Adapter::session(), 23, str, bytes, sl);
assert(status == PEP_STATUS_OK);
Adapter::session(Adapter::release);
Adapter::session.release();
return 0;
}

@ -158,6 +158,11 @@ int test_pEp_init(TestUnitSwarm &pity, TextContext *ctx)
pity.log("HOME : " + std::string(getenv("HOME")));
pity.log("PUD : " + std::string(::per_user_directory()));
pity.log("PMD : " + std::string(::per_machine_directory()));
pEp::Adapter::session.initialize(
pEp::Adapter::SyncModes::Async,
false,
test_messageToSend,
test_notifyHandshake);
return 0;
}
@ -167,19 +172,15 @@ int test_create_myself(TestUnitSwarm &pity, TextContext *ctx)
pity.log("updating or creating identity for me");
ctx->own_ident = createOwnIdent(ctx->own_name);
::PEP_STATUS status = ::myself(Adapter::session(), ctx->own_ident.get());
// Create cpt
// PITYASSERT(ctx->cpt != nullptr, "");
// ctx->cpt->ident = createCptIdent(ctx->getCpt().addr);
pEp::throw_status(status);
return 0;
}
int test_start_sync(TestUnitSwarm &pity, TextContext *ctx)
{
Adapter::sync_initialize(SyncModes::Off, test_messageToSend, test_notifyHandshake, false);
Adapter::session
.initialize(Adapter::SyncModes::Async, false, test_messageToSend, test_notifyHandshake);
processsAllMessages();
::adapter_group_init();
return 0;
}
@ -487,14 +488,5 @@ int main(int argc, char *argv[])
swarm.addTestUnit(i, TestUnitSwarm("test_receive_all", test_receive_all));
}
// ------------------------------------------------------------------------------------
// swarm.addTestUnit(2, TestUnitSwarm("test_pEp_init", test_pEp_init));
// swarm.addTestUnit(2, TestUnitSwarm("test_create_myself", test_create_myself));
// swarm.addTestUnit(2, TestUnitSwarm("test_tofu_react", test_tofu_react));
// swarm.addTestUnit(2, TestUnitSwarm("test_start_sync", test_start_sync));
// swarm.addTestUnit(2, TestUnitSwarm("test_group_join", test_group_join));
// swarm.addTestUnit(2, TestUnitSwarm("test_receive_groupmessage", test_receive_groupmessage));
// ------------------------------------------------------------------------------------
suite.run();
}

@ -82,13 +82,11 @@ void tofu_receiveAndReply(TestUnitSwarm &pity, TextContext *ctx)
int test_create_myself(TestUnitSwarm &pity, TextContext *ctx)
{
Adapter::session.initialize();
// Create new identity
pity.log("updating or creating identity for me");
ctx->own_ident = createOwnIdent(ctx->own_name);
::PEP_STATUS status = ::myself(Adapter::session(), ctx->own_ident.get());
// Create cpt
// PITYASSERT(ctx->cpt != nullptr, "");
// ctx->cpt->ident = createCptIdent(ctx->getCpt().addr);
pEp::throw_status(status);
return 0;
}

@ -28,7 +28,7 @@ PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, ::sync_hands
int main(int argc, char **argv)
{
pEp::Test::setup(argc, argv);
Adapter::session.initialize(Adapter::SyncModes::Async, false);
// Create new identity
TESTLOG("updating or creating identity for me");
::pEp_identity *me = ::new_identity("alice@peptest.ch", NULL, "23", "Who the F* is Alice");
@ -44,11 +44,10 @@ int main(int argc, char **argv)
TESTLOG(i);
TESTLOG("SYNC START");
TESTLOG("starting the adapter including sync");
Adapter::sync_initialize(Adapter::SyncModes::Off, messageToSend, notifyHandshake, false);
Adapter::start_sync();
TESTLOG("SYNC STOP");
Utils::sleep_millis(500);
Adapter::shutdown();
Adapter::stop_sync();
}
return 0;
}

@ -101,7 +101,7 @@ int tofu(PityUnit<PityPerspective> &pity, PityPerspective *ctx, bool init)
pity.log("partner: " + ctx->getCpt().addr);
pity.log("HOME : " + std::string(getenv("HOME")));
pity.log("PUD : " + std::string(::per_user_directory()));
Adapter::session.initialize();
// Create new identity
pity.log("updating or creating identity for me");

Loading…
Cancel
Save