diff --git a/Makefile.conf b/Makefile.conf index 28496ff..70e6875 100644 --- a/Makefile.conf +++ b/Makefile.conf @@ -7,7 +7,7 @@ HERE:=$(dir $(lastword $(MAKEFILE_LIST))) PREFIX=$(HOME) -CXXFLAGS=-std=c++11 -fPIC -O0 $(ENGINE_INC) +CXXFLAGS1=-std=c++11 -fPIC -O0 $(ENGINE_INC) # Build target BUILD_FOR:=$(shell uname) @@ -47,3 +47,7 @@ endif ifdef BUILD_CONFIG include $(BUILD_CONFIG) endif + +ifndef ENGINE_TEST + ENGINE_TEST = \"$(HOME)/dev/pEpEngine/test\" +endif diff --git a/passphrase_cache.cc b/passphrase_cache.cc index 3d1815b..c3b46e9 100644 --- a/passphrase_cache.cc +++ b/passphrase_cache.cc @@ -156,7 +156,7 @@ namespace pEp { PEP_STATUS PassphraseCache::ensure_passphrase(PEP_SESSION session, std::string fpr) { - PEP_STATUS status = PEP_STATUS_OK; + PEP_STATUS status; for_each_passphrase([&](std::string passphrase) { status = ::config_passphrase(session, passphrase.c_str()); diff --git a/passphrase_cache.hxx b/passphrase_cache.hxx index 17d9288..cb97d7a 100644 --- a/passphrase_cache.hxx +++ b/passphrase_cache.hxx @@ -1,4 +1,3 @@ -#pragma once #include "passphrase_cache.hh" namespace pEp { diff --git a/test/Makefile b/test/Makefile index 5dd5120..05b56dc 100644 --- a/test/Makefile +++ b/test/Makefile @@ -2,28 +2,15 @@ include ../Makefile.conf LDFLAGS=-L../ $(ENGINE_LIB) LDLIBS=-lstdc++ -lpEpEngine -lpEpAdapter -CXXFLAGS+=-I../ +CXXFLAGS+=-I../ $(ENGINE_INC) -std=c++11 -DENGINE_TEST=$(ENGINE_TEST) -.PHONY=all, test_adapter, test_adapter_cxx, test_library +SRC=$(wildcard test_*.cc) +TST=$(subst .cc,,$(SRC)) -all: test_adapter test_adapter_cxx test_library test_passphrase_cache test_semaphore test_message_cache +all: $(TST) -test_adapter: test_adapter.cc ../libpEpAdapter.a - -test_adapter_cxx: test_adapter_cxx.cc ../libpEpAdapter.a - -test_library: test_library.cc ../libpEpAdapter.a - -test_passphrase_cache: test_passphrase_cache.cc ../libpEpAdapter.a - -test_semaphore: test_semaphore.cc ../libpEpAdapter.a - -test_message_cache: test_message_cache.cc ../libpEpAdapter.a +%: %.cc ../libpEpAdapter.a clean: - rm -vf test_adapter - rm -rvf test_adapter.dSYM - rm -vf test_adapter_cxx - rm -rvf test_adapter_cxx.dSYM - rm -vf test_library - rm -rvf test_library.dSYM + rm -f $(TST) + rm -f *.dSYM diff --git a/test/test_ensure_passphrase.cc b/test/test_ensure_passphrase.cc new file mode 100644 index 0000000..907124e --- /dev/null +++ b/test/test_ensure_passphrase.cc @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +#include + +#include "Adapter.hh" +#include "passphrase_cache.hh" +#include "status_to_string.hh" + +#include +#include + +using namespace pEp; +using namespace pEp::Adapter; +using namespace std; + +void test() +{ + passphrase_cache.add("erwin"); + passphrase_cache.add("cathy"); + passphrase_cache.add("bob"); + + const char* bob_filename = ENGINE_TEST "/test_keys/bob-primary-with-password-bob-subkey-without.pgp"; + const char* bob_fpr = "5C76378A62B04CF3F41BEC8D4940FC9FA1878736"; + + const char* erwin_filename = ENGINE_TEST "/test_keys/erwin_normal_encrypted.pgp"; + const char* erwin_fpr = "CBA968BC01FCEB89F04CCF155C5E9E3F0420A570"; + + 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* erwin = ::new_identity("erwin@example.org", erwin_fpr, "BOB", "Bob is Erwin"); + status = ::set_own_key(session(), erwin, erwin_fpr); + + ::free_identity(bob); + ::free_identity(erwin); + + session(Adapter::release); +} + +int main() +{ + char path[MAXPATHLEN+1]; + const char *templ = "/tmp/test_ensure_passphrase.XXXXXXXXXXXX"; + strcpy(path, templ); + char *tmpdir = mkdtemp(path); + assert(tmpdir); + chdir(tmpdir); + setenv("HOME", path, 1); + cerr << "test directory: " << path << endl; + + test(); + return 0; +} +