Browse Source

LIB-13: YES, diff breaking cahnge, reformat tests. clang-format now or never!

pull/8/head
heck 4 years ago
parent
commit
9b2defe5fb
  1. 3
      .clang-format
  2. 32
      test/framework.cc
  3. 10
      test/framework.hh
  4. 80
      test/test_adapter_cxx.cc
  5. 6
      test/test_ensure_passphrase.cc
  6. 44
      test/test_leave_device_group.cc
  7. 156
      test/test_library.cc
  8. 23
      test/test_message_cache.cc
  9. 55
      test/test_passphrase_cache.cc
  10. 27
      test/test_semaphore.cc

3
.clang-format

@ -1,11 +1,13 @@
BasedOnStyle: LLVM BasedOnStyle: LLVM
Language: Cpp Language: Cpp
Standard: c++14
DerivePointerAlignment: true DerivePointerAlignment: true
SortIncludes: false SortIncludes: false
ReflowComments: false ReflowComments: false
PointerAlignment: Left PointerAlignment: Left
AlignAfterOpenBracket: AlwaysBreak AlignAfterOpenBracket: AlwaysBreak
AlignOperands: AlignAfterOperator AlignOperands: AlignAfterOperator
BreakConstructorInitializers: AfterColon
AlignTrailingComments: true AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false AllowAllParametersOfDeclarationOnNextLine: false
@ -36,3 +38,4 @@ SpaceAfterTemplateKeyword: false
AccessModifierOffset: -4 AccessModifierOffset: -4
AllowShortBlocksOnASingleLine: Always AllowShortBlocksOnASingleLine: Always
IndentPPDirectives: BeforeHash IndentPPDirectives: BeforeHash
Cpp11BracedListStyle: false

32
test/framework.cc

@ -28,7 +28,7 @@ namespace pEp {
namespace Test { namespace Test {
using namespace Adapter; using namespace Adapter;
void setup(vector<string>& args) void setup(vector<string> &args)
{ {
#ifdef WIN32 #ifdef WIN32
string dir = getenv("TEMP"); string dir = getenv("TEMP");
@ -45,17 +45,15 @@ namespace pEp {
cout << "usage: " << args[0] << " [--dir HOME]" << endl; cout << "usage: " << args[0] << " [--dir HOME]" << endl;
#endif #endif
exit(0); exit(0);
} } else if (args[1] == "--dir" && args.size() == 3) {
else if (args[1] == "--dir" && args.size() == 3) {
dir = args[2]; dir = args[2];
} } else {
else {
cerr << "illegal parameter" << endl; cerr << "illegal parameter" << endl;
exit(1); exit(1);
} }
} }
char _path[MAXPATHLEN+1]; char _path[MAXPATHLEN + 1];
const char *templ = dir.c_str(); const char *templ = dir.c_str();
strcpy(_path, templ); strcpy(_path, templ);
mkdtemp(_path); mkdtemp(_path);
@ -71,8 +69,8 @@ namespace pEp {
void setup(int argc, char **argv) void setup(int argc, char **argv)
{ {
vector<string> args{(size_t) argc}; vector<string> args{ (size_t)argc };
for (int i=0; i<argc; ++i) for (int i = 0; i < argc; ++i)
args[i] = argv[i]; args[i] = argv[i];
setup(args); setup(args);
@ -81,7 +79,7 @@ namespace pEp {
void import_key_from_file(string filename) void import_key_from_file(string filename)
{ {
ifstream f(filename, ifstream::in); ifstream f(filename, ifstream::in);
string key{istreambuf_iterator<char>(f), istreambuf_iterator<char>()}; string key{ istreambuf_iterator<char>(f), istreambuf_iterator<char>() };
::identity_list *il = NULL; ::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); assert(status == PEP_KEY_IMPORTED);
@ -95,14 +93,18 @@ namespace pEp {
Identity make_identity(::pEp_identity *ident) Identity make_identity(::pEp_identity *ident)
{ {
return shared_ptr<::pEp_identity>(ident , ::free_identity); return shared_ptr<::pEp_identity>(ident, ::free_identity);
} }
Message mime_parse(string text) Message mime_parse(string text)
{ {
::message *msg; ::message *msg;
bool has_possible_pEp_msg; bool has_possible_pEp_msg;
PEP_STATUS status = ::mime_decode_message(text.c_str(), text.length(), &msg, &has_possible_pEp_msg); PEP_STATUS status = ::mime_decode_message(
text.c_str(),
text.length(),
&msg,
&has_possible_pEp_msg);
throw_status(status); throw_status(status);
return make_message(msg); return make_message(msg);
} }
@ -143,8 +145,7 @@ namespace pEp {
text += _text; text += _text;
pEp_free(_text); pEp_free(_text);
return text; return text;
} } else if (string("application/pEp.distribution") == a->mime_type) {
else if (string("application/pEp.distribution") == a->mime_type) {
char *_text; 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); throw_status(status);
@ -175,7 +176,6 @@ namespace pEp {
void Transport::send(Message msg) void Transport::send(Message msg)
{ {
mkdir(outbox_path.c_str(), 0770); mkdir(outbox_path.c_str(), 0770);
} }
}; }; // namespace Test
}; }; // namespace pEp

10
test/framework.hh

@ -14,15 +14,15 @@ namespace pEp {
using namespace std; using namespace std;
// manually set up test // manually set up test
void setup(vector<string>& args); void setup(vector<string> &args);
// call this in main() for auto set up // call this in main() for auto set up
void setup(int argc=1, char **argv=nullptr); void setup(int argc = 1, char **argv = nullptr);
void import_key_from_file(string filename); void import_key_from_file(string filename);
using Message = shared_ptr<::message>; using Message = shared_ptr<::message>;
using Identity= shared_ptr<::pEp_identity>; using Identity = shared_ptr<::pEp_identity>;
// use this instead of constructor to auto assign ::free_message as // use this instead of constructor to auto assign ::free_message as
// deleter // deleter
@ -57,7 +57,7 @@ namespace pEp {
extern Transport transport; extern Transport transport;
extern string path; extern string path;
}; }; // namespace Test
}; }; // namespace pEp
#endif // LIBPEPADAPTER_FRAMEWORK_HH #endif // LIBPEPADAPTER_FRAMEWORK_HH

80
test/test_adapter_cxx.cc

@ -10,50 +10,60 @@
using namespace pEp::Adapter; using namespace pEp::Adapter;
PEP_STATUS messageToSend(struct _message *msg) { PEP_STATUS messageToSend(struct _message *msg)
pEpLog("called"); {
return PEP_STATUS_OK; pEpLog("called");
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; pEpLog("called");
return PEP_STATUS_OK;
} }
class JNISync { class JNISync {
public: public:
void onSyncStartup() { void onSyncStartup()
pEpLog("called"); {
} pEpLog("called");
}
void onSyncShutdown() { void onSyncShutdown()
pEpLog("called"); {
} pEpLog("called");
}
} o; } o;
int main(int argc, char **argv) { int main(int argc, char **argv)
{
pEp::Test::setup(argc, argv); pEp::Test::setup(argc, argv);
// Create new identity // Create new identity
pEpLog("updating or creating identity for me"); 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); assert(me);
PEP_STATUS status = myself(session(), me); PEP_STATUS status = myself(session(), me);
free_identity(me); free_identity(me);
pEp::throw_status(status); pEp::throw_status(status);
// start and stop sync repeatedly // start and stop sync repeatedly
useconds_t sleepuSec = 1000 * 100; useconds_t sleepuSec = 1000 * 100;
unsigned long long int nrIters = 1000 * 1000 * 1000; unsigned long long int nrIters = 1000 * 1000 * 1000;
for (int i = 0; i < nrIters; i++) { for (int i = 0; i < nrIters; i++) {
pEpLog("RUN NR: "); pEpLog("RUN NR: ");
pEpLog(i); pEpLog(i);
pEpLog("SYNC START"); pEpLog("SYNC START");
pEpLog("starting the adapter including sync"); pEpLog("starting the adapter including sync");
startup<JNISync>(messageToSend, notifyHandshake, &o, &JNISync::onSyncStartup, &JNISync::onSyncShutdown); startup<JNISync>(
pEpLog("SYNC STOP"); messageToSend,
usleep(sleepuSec); notifyHandshake,
shutdown(); &o,
} &JNISync::onSyncStartup,
return 0; &JNISync::onSyncShutdown);
pEpLog("SYNC STOP");
usleep(sleepuSec);
shutdown();
}
return 0;
} }

6
test/test_ensure_passphrase.cc

@ -20,7 +20,7 @@ using namespace pEp;
using namespace pEp::Adapter; using namespace pEp::Adapter;
using namespace std; using namespace std;
int main(int argc, char **argv) int main(int argc, char** argv)
{ {
Test::setup(argc, argv); Test::setup(argc, argv);
@ -28,7 +28,8 @@ int main(int argc, char **argv)
passphrase_cache.add("cathy"); passphrase_cache.add("cathy");
passphrase_cache.add("bob"); passphrase_cache.add("bob");
const char* bob_filename = ENGINE_TEST "/test_keys/bob-primary-with-password-bob-subkey-without.pgp"; const char* bob_filename = ENGINE_TEST
"/test_keys/bob-primary-with-password-bob-subkey-without.pgp";
const char* bob_fpr = "5C76378A62B04CF3F41BEC8D4940FC9FA1878736"; const char* bob_fpr = "5C76378A62B04CF3F41BEC8D4940FC9FA1878736";
const char* erwin_filename = ENGINE_TEST "/test_keys/erwin_normal_encrypted.pgp"; const char* erwin_filename = ENGINE_TEST "/test_keys/erwin_normal_encrypted.pgp";
@ -55,4 +56,3 @@ int main(int argc, char **argv)
return 0; return 0;
} }

44
test/test_leave_device_group.cc

@ -12,23 +12,19 @@ using namespace pEp;
using namespace pEp::Adapter; using namespace pEp::Adapter;
using namespace std; using namespace std;
vector<string> expected_msg = { vector<string> expected_msg = { "synchronizeGroupKeys",
"synchronizeGroupKeys", "groupKeysUpdate",
"groupKeysUpdate", "initUnledGroupKeyReset",
"initUnledGroupKeyReset", "beacon",
"beacon", "beacon" };
"beacon"
}; vector<::sync_handshake_signal> expected_notification = { SYNC_NOTIFY_IN_GROUP,
SYNC_NOTIFY_START,
vector<::sync_handshake_signal> expected_notification = { SYNC_NOTIFY_SOLE,
SYNC_NOTIFY_IN_GROUP, SYNC_NOTIFY_START,
SYNC_NOTIFY_START, SYNC_NOTIFY_STOP };
SYNC_NOTIFY_SOLE,
SYNC_NOTIFY_START, PEP_STATUS test_messageToSend(::message* _msg)
SYNC_NOTIFY_STOP
};
PEP_STATUS test_messageToSend(::message *_msg)
{ {
static auto actual = expected_msg.begin(); static auto actual = expected_msg.begin();
@ -41,7 +37,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(); static auto actual = expected_notification.begin();
@ -53,7 +49,7 @@ PEP_STATUS test_notifyHandshake(pEp_identity *_me, pEp_identity *_partner, sync_
return PEP_STATUS_OK; return PEP_STATUS_OK;
} }
int main(int argc, char **argv) int main(int argc, char** argv)
{ {
Test::setup(argc, argv); Test::setup(argc, argv);
session(); session();
@ -63,7 +59,8 @@ int main(int argc, char **argv)
passphrase_cache.add("erwin"); passphrase_cache.add("erwin");
passphrase_cache.add("bob"); passphrase_cache.add("bob");
const char* bob_filename = ENGINE_TEST "/test_keys/bob-primary-with-password-bob-subkey-without.pgp"; const char* bob_filename = ENGINE_TEST
"/test_keys/bob-primary-with-password-bob-subkey-without.pgp";
const char* bob_fpr = "5C76378A62B04CF3F41BEC8D4940FC9FA1878736"; const char* bob_fpr = "5C76378A62B04CF3F41BEC8D4940FC9FA1878736";
const char* erwin_filename = ENGINE_TEST "/test_keys/erwin_normal_encrypted.pgp"; const char* erwin_filename = ENGINE_TEST "/test_keys/erwin_normal_encrypted.pgp";
@ -72,14 +69,16 @@ int main(int argc, char **argv)
Test::import_key_from_file(bob_filename); Test::import_key_from_file(bob_filename);
Test::import_key_from_file(erwin_filename); Test::import_key_from_file(erwin_filename);
Test::Identity bob = Test::make_identity(::new_identity("bob@example.org", bob_fpr, "BOB", "Bob Dog")); 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(session(), bob.get(), bob_fpr);
assert(status == PEP_STATUS_OK); assert(status == PEP_STATUS_OK);
status = ::enable_identity_for_sync(session(), bob.get()); status = ::enable_identity_for_sync(session(), bob.get());
assert(status == PEP_STATUS_OK); assert(status == PEP_STATUS_OK);
Test::Identity erwin = Test::make_identity(::new_identity("erwin@example.org", erwin_fpr, "BOB", "Bob is Erwin")); 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(session(), erwin.get(), erwin_fpr);
assert(status == PEP_STATUS_OK); assert(status == PEP_STATUS_OK);
@ -118,4 +117,3 @@ int main(int argc, char **argv)
return 0; return 0;
} }

156
test/test_library.cc

@ -9,108 +9,96 @@ using namespace pEp;
// Producer's data: // Producer's data:
class P class P {
{
public: public:
P(int i) P(int i) : data{ new char[64] }
: data{new char[64]} {
{ snprintf(data, 63, "%i", i);
snprintf(data, 63, "%i", i); }
}
P(const P&) = delete;
P(const P&) = delete; void operator=(const P&) = delete;
void operator=(const P&) = delete;
~P()
~P() {
{ std::cerr << "~P(): data=" << (data ? data : "(NULL)") << '\n';
std::cerr << "~P(): data=" << (data ? data : "(NULL)" ) << '\n'; delete[] data;
delete[] data; }
}
char* data;
char* data;
}; };
// Consumer's data: // Consumer's data:
class C class C {
{
public: public:
C(int _i) : i(_i) {} C(int _i) : i(_i) {}
int i; int i;
}; };
pc_container<P,C> pc; pc_container<P, C> pc;
void consumer_thread() void consumer_thread()
{ {
bool keep_running = true; bool keep_running = true;
int sum = 0; int sum = 0;
while(keep_running) while (keep_running) {
{ for (auto& q : pc) {
for(auto& q : pc) switch (q.state()) {
{ case PC_State::Created: {
switch(q.state()) const int value = atoi(q.pdata->data);
{ if (value < 0) {
case PC_State::Created: std::cerr << "Q\n";
{ keep_running = false;
const int value = atoi( q.pdata->data ); } else {
if(value<0) std::cerr << "C";
{ q.cdata = new C(value);
std::cerr << "Q\n"; sum += q.cdata->i;
keep_running = false; }
}else{ break;
std::cerr << "C"; }
q.cdata = new C( value ); case PC_State::Deleted: {
sum += q.cdata->i; std::cerr << "D";
} sum -= q.cdata->i;
break; delete q.cdata;
} break;
case PC_State::Deleted: }
{ case PC_State::Changed: {
std::cerr << "D"; std::cerr << "X";
sum -= q.cdata->i; sum -= q.cdata->i;
delete q.cdata; delete q.cdata;
break; q.cdata = new C(atoi(q.pdata->data));
} sum += q.cdata->i;
case PC_State::Changed: break;
{ }
std::cerr << "X"; default:
sum -= q.cdata->i; throw "Illegal state";
delete q.cdata; }
q.cdata = new C( atoi( q.pdata->data ) ); }
sum += q.cdata->i; }
break;
} std::cout << "Consumer sum: " << sum << ".\n";
default: throw "Illegal state";
}
}
}
std::cout << "Consumer sum: " << sum << ".\n";
} }
int main() int main()
{ {
for(int i=0; i<10; ++i) for (int i = 0; i < 10; ++i) {
{ pc.insert(new P(i));
pc.insert( new P(i) ); }
}
std::thread t{ &consumer_thread }; std::thread t{ &consumer_thread };
for(int i=10; i<100; ++i) for (int i = 10; i < 100; ++i) {
{ pc.insert(new P(i));
pc.insert( new P(i) ); }
}
while( !pc.empty() ) while (!pc.empty()) {
{ auto q = pc.begin();
auto q = pc.begin(); delete q->pdata;
delete q->pdata; pc.erase(q);
pc.erase( q ); }
}
pc.insert( new P(-1) ); pc.insert(new P(-1));
t.join(); t.join();
} }

23
test/test_message_cache.cc

@ -25,7 +25,11 @@ int main(int argc, char **argv)
::message *src = nullptr; ::message *src = nullptr;
bool has_possible_pEp_msg; bool has_possible_pEp_msg;
PEP_STATUS status = MessageCache::cache_mime_decode_message(mime, strlen(mime), &src, &has_possible_pEp_msg); PEP_STATUS status = MessageCache::cache_mime_decode_message(
mime,
strlen(mime),
&src,
&has_possible_pEp_msg);
assert(status == PEP_STATUS_OK); assert(status == PEP_STATUS_OK);
status = ::myself(pEp::Adapter::session(), src->from); status = ::myself(pEp::Adapter::session(), src->from);
@ -38,7 +42,13 @@ int main(int argc, char **argv)
src->dir = PEP_dir_outgoing; src->dir = PEP_dir_outgoing;
::message *dst = nullptr; ::message *dst = nullptr;
status = MessageCache::cache_encrypt_message(pEp::Adapter::session(), src, nullptr, &dst, PEP_enc_PEP, 0); status = MessageCache::cache_encrypt_message(
pEp::Adapter::session(),
src,
nullptr,
&dst,
PEP_enc_PEP,
0);
assert(status != PEP_ILLEGAL_VALUE); assert(status != PEP_ILLEGAL_VALUE);
assert(src->longmsg == nullptr); assert(src->longmsg == nullptr);
@ -69,7 +79,13 @@ int main(int argc, char **argv)
PEP_decrypt_flags_t flags = 0; PEP_decrypt_flags_t flags = 0;
stringlist_t *keylist = nullptr; stringlist_t *keylist = nullptr;
status = MessageCache::cache_decrypt_message(pEp::Adapter::session(), src, &dst, &keylist, &rating, &flags); status = MessageCache::cache_decrypt_message(
pEp::Adapter::session(),
src,
&dst,
&keylist,
&rating,
&flags);
assert(status != PEP_ILLEGAL_VALUE); assert(status != PEP_ILLEGAL_VALUE);
assert(src->longmsg == nullptr); assert(src->longmsg == nullptr);
@ -95,4 +111,3 @@ int main(int argc, char **argv)
pEp::Adapter::session(pEp::Adapter::release); pEp::Adapter::session(pEp::Adapter::release);
return 0; return 0;
} }

55
test/test_passphrase_cache.cc

@ -8,17 +8,17 @@
#include "status_to_string.hh" #include "status_to_string.hh"
extern "C" { 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"; std::cout << "called api_test1\n";
return PEP_WRONG_PASSPHRASE; 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"; std::cout << "called api_test2\n";
return PEP_STATUS_OK; return PEP_STATUS_OK;
} }
}; };
int main(int argc, char **argv) int main(int argc, char **argv)
@ -30,21 +30,36 @@ int main(int argc, char **argv)
int n = 42; int n = 42;
::stringlist_t *sl = NULL; ::stringlist_t *sl = NULL;
pEp::PassphraseCache cache{2, std::chrono::seconds(1)}; pEp::PassphraseCache cache{ 2, std::chrono::seconds(1) };
cache.add("say"); cache.add("say");
cache.add("hello"); cache.add("hello");
cache.add("world"); cache.add("world");
std::cout << "expected: two passphrases\n"; std::cout << "expected: two passphrases\n";
cache.for_each_passphrase([&](std::string passphrase){std::cout << "'" << passphrase << "'\n"; return false;}); cache.for_each_passphrase([&](std::string passphrase) {
std::cout << "'" << passphrase << "'\n";
return false;
});
std::cout << "expected: one passphrase\n"; std::cout << "expected: one passphrase\n";
cache.for_each_passphrase([&](std::string passphrase){std::cout << "'" << passphrase << "'\n"; return passphrase != "";}); cache.for_each_passphrase([&](std::string passphrase) {
std::cout << "'" << passphrase << "'\n";
return passphrase != "";
});
std::cout << "expected: two passphrases but reverse order\n"; std::cout << "expected: two passphrases but reverse order\n";
cache.for_each_passphrase([&](std::string passphrase){std::cout << "'" << passphrase << "'\n"; return false;}); cache.for_each_passphrase([&](std::string passphrase) {
std::cout << "'" << passphrase << "'\n";
PEP_STATUS status = cache.api(api_test1, pEp::Adapter::session(), "23", bytes, n, (::stringlist_t *) NULL); return false;
});
PEP_STATUS status = cache.api(
api_test1,
pEp::Adapter::session(),
"23",
bytes,
n,
(::stringlist_t *)NULL);
assert(status == PEP_WRONG_PASSPHRASE); assert(status == PEP_WRONG_PASSPHRASE);
status = cache.api(api_test2, pEp::Adapter::session(), n, str, bytes, sl); status = cache.api(api_test2, pEp::Adapter::session(), n, str, bytes, sl);
assert(status == PEP_STATUS_OK); assert(status == PEP_STATUS_OK);
@ -57,8 +72,8 @@ int main(int argc, char **argv)
while (1) { while (1) {
std::cout << "'" << _cache.latest_passphrase(_cache) << "'\n"; std::cout << "'" << _cache.latest_passphrase(_cache) << "'\n";
} }
} catch (std::underflow_error &) {
} }
catch (std::underflow_error&) { }
pEp::passphrase_cache.add("hello"); pEp::passphrase_cache.add("hello");
pEp::passphrase_cache.add("world"); pEp::passphrase_cache.add("world");
@ -71,7 +86,10 @@ int main(int argc, char **argv)
sleep(2); sleep(2);
std::cout << "expected: no passphrase\n"; std::cout << "expected: no passphrase\n";
cache.for_each_passphrase([&](std::string passphrase){std::cout << "'" << passphrase << "'\n"; return false;}); cache.for_each_passphrase([&](std::string passphrase) {
std::cout << "'" << passphrase << "'\n";
return false;
});
status = cache.api(api_test1, pEp::Adapter::session(), str, bytes, n, sl); status = cache.api(api_test1, pEp::Adapter::session(), str, bytes, n, sl);
assert(status == PEP_WRONG_PASSPHRASE); assert(status == PEP_WRONG_PASSPHRASE);
@ -81,4 +99,3 @@ int main(int argc, char **argv)
pEp::Adapter::session(pEp::Adapter::release); pEp::Adapter::session(pEp::Adapter::release);
return 0; return 0;
} }

27
test/test_semaphore.cc

@ -10,26 +10,25 @@ int main()
{ {
Semaphore semaphore; Semaphore semaphore;
thread thread1([&](){ thread thread1([&]() {
cout << "1: before stop\n"; cout << "1: before stop\n";
semaphore.stop(); semaphore.stop();
cout << "1: now on stop\n"; cout << "1: now on stop\n";
semaphore.try_wait(); semaphore.try_wait();
cout << "1: and on go again\n"; cout << "1: and on go again\n";
semaphore.try_wait(); semaphore.try_wait();
cout << "1: keep going\n"; cout << "1: keep going\n";
}); });
sleep(1); sleep(1);
thread thread2([&](){ thread thread2([&]() {
cout << "2: setting go\n"; cout << "2: setting go\n";
semaphore.go(); semaphore.go();
}); });
thread1.join(); thread1.join();
thread2.join(); thread2.join();
return 0; return 0;
} }

Loading…
Cancel
Save