Browse Source

semaphore test

synchronous
Volker Birk 5 years ago
parent
commit
aa1f7370c3
  1. 3
      callback_dispatcher.cc
  2. 4
      test/Makefile
  3. 35
      test/test_semaphore.cc

3
callback_dispatcher.cc

@ -100,9 +100,8 @@ namespace pEp {
PEP_STATUS status = PassphraseCache::messageToSend(passphrase_cache, Adapter::session());
// if the cache has no valid passphrase ask the app
if (status == PEP_PASSPHRASE_REQUIRED || status == PEP_WRONG_PASSPHRASE) {
if (status == PEP_PASSPHRASE_REQUIRED || status == PEP_WRONG_PASSPHRASE)
semaphore.stop();
}
// the pEp engine must try again
return status;

4
test/Makefile

@ -6,7 +6,7 @@ CXXFLAGS+=-I../
.PHONY=all, test_adapter, test_adapter_cxx, test_library
all: test_adapter test_adapter_cxx test_library test_passphrase_cache
all: test_adapter test_adapter_cxx test_library test_passphrase_cache test_semaphore
test_adapter: test_adapter.cc ../libpEpAdapter.a
@ -16,6 +16,8 @@ test_library: test_library.cc ../libpEpAdapter.a
test_passphrase_cache: test_passphrase_cache.cc ../libpEpAdapter.a
test_semaphore: test_semaphore.cc ../libpEpAdapter.a
clean:
rm -vf test_adapter
rm -rvf test_adapter.dSYM

35
test/test_semaphore.cc

@ -0,0 +1,35 @@
#include <iostream>
#include <thread>
#include <unistd.h>
#include "Semaphore.hh"
using namespace std;
using namespace pEp;
int main()
{
Semaphore semaphore;
thread thread1([&](){
cout << "1: before stop\n";
semaphore.stop();
cout << "1: now on stop\n";
semaphore.try_wait();
cout << "1: and on go again\n";
semaphore.try_wait();
cout << "1: keeping going\n";
});
sleep(1);
thread thread2([&](){
cout << "2: setting go\n";
semaphore.go();
});
thread1.join();
thread2.join();
return 0;
}
Loading…
Cancel
Save