forked from pEp.foundation/libpEpAdapter
tests are using tmp dirs
parent
358e3ccc3c
commit
48d6323ff5
2
Makefile
2
Makefile
|
@ -28,8 +28,6 @@ DEPENDS=$(subst .cc,.d,$(SOURCE))
|
|||
|
||||
all: $(TARGET)
|
||||
|
||||
-include Makefile.protocols
|
||||
|
||||
%.d: %.cc
|
||||
@set -e; rm -f $@; \
|
||||
$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< > $@.$$$$; \
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
HERE:=$(dir $(lastword $(MAKEFILE_LIST)))
|
||||
|
||||
|
||||
PREFIX=$(HOME)
|
||||
CXXFLAGS1=-std=c++11 -fPIC -O0 $(ENGINE_INC)
|
||||
PREFIX?=$(HOME)
|
||||
CXXFLAGS+=-std=c++11 -fPIC -O0
|
||||
|
||||
# Build target
|
||||
BUILD_FOR:=$(shell uname)
|
||||
|
@ -29,8 +29,8 @@ else
|
|||
endif
|
||||
|
||||
######### Engine #########
|
||||
ENGINE_LIB_PATH=$(HOME)/lib
|
||||
ENGINE_INC_PATH=$(HOME)/include
|
||||
ENGINE_LIB_PATH=$(PREFIX)/lib
|
||||
ENGINE_INC_PATH=$(PREFIX)/include
|
||||
|
||||
######### Overrides #########
|
||||
-include $(HERE)/local.conf
|
||||
|
@ -51,3 +51,5 @@ endif
|
|||
ifndef ENGINE_TEST
|
||||
ENGINE_TEST = \"$(HOME)/dev/pEpEngine/test\"
|
||||
endif
|
||||
|
||||
CXXFLAGS += $(ENGINE_INC)
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <iostream>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
#include <pEp/keymanagement.h>
|
||||
#include "pEpLog.hh"
|
||||
|
||||
|
@ -25,6 +26,15 @@ PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handsha
|
|||
|
||||
int main()
|
||||
{
|
||||
char path[MAXPATHLEN+1];
|
||||
const char *templ = "/tmp/test_adapter.XXXXXXXXXXXX";
|
||||
strcpy(path, templ);
|
||||
char *tmpdir = mkdtemp(path);
|
||||
assert(tmpdir);
|
||||
chdir(tmpdir);
|
||||
setenv("HOME", path, 1);
|
||||
cerr << "test directory: " << path << endl;
|
||||
|
||||
// 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");
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
// small unittest program for libpEpAdapter
|
||||
// TODO: use Gtest or the like for more modular unit tests!
|
||||
|
||||
#include "pc_container.hh"
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
|
|
@ -1,18 +1,26 @@
|
|||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <sys/param.h>
|
||||
#include <unistd.h>
|
||||
#include "message_cache.hh"
|
||||
#include "Adapter.hh"
|
||||
|
||||
using namespace std;
|
||||
using namespace pEp;
|
||||
|
||||
int main()
|
||||
{
|
||||
PEP_SESSION session;
|
||||
PEP_STATUS status = ::init(&session, nullptr, nullptr);
|
||||
assert(status == PEP_STATUS_OK);
|
||||
char path[MAXPATHLEN+1];
|
||||
const char *templ = "/tmp/test_message_cache.XXXXXXXXXXXX";
|
||||
strcpy(path, templ);
|
||||
char *tmpdir = mkdtemp(path);
|
||||
assert(tmpdir);
|
||||
chdir(tmpdir);
|
||||
setenv("HOME", path, 1);
|
||||
cerr << "test directory: " << path << endl;
|
||||
|
||||
pEp_identity *alice = ::new_identity("alice@mail.com", nullptr, PEP_OWN_USERID, "Alice");
|
||||
::myself(session, alice);
|
||||
::myself(pEp::Adapter::session(), alice);
|
||||
|
||||
char *mime = strdup("From: Alice <alice@mail.com>\n"
|
||||
"To: Bob <bob@mail.com>\n"
|
||||
|
@ -24,20 +32,20 @@ int main()
|
|||
|
||||
::message *src = nullptr;
|
||||
bool has_possible_pEp_msg;
|
||||
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);
|
||||
|
||||
status = ::myself(session, src->from);
|
||||
status = ::myself(pEp::Adapter::session(), src->from);
|
||||
assert(status == PEP_STATUS_OK);
|
||||
|
||||
::update_identity(session, src->to->ident);
|
||||
::update_identity(pEp::Adapter::session(), src->to->ident);
|
||||
assert(status == PEP_STATUS_OK);
|
||||
|
||||
pEp_identity *bob = identity_dup(src->to->ident);
|
||||
|
||||
src->dir = PEP_dir_outgoing;
|
||||
::message *dst = nullptr;
|
||||
status = MessageCache::cache_encrypt_message(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(src->longmsg == nullptr);
|
||||
|
@ -68,7 +76,7 @@ int main()
|
|||
PEP_decrypt_flags_t flags = 0;
|
||||
stringlist_t *keylist = nullptr;
|
||||
|
||||
status = MessageCache::cache_decrypt_message(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(src->longmsg == nullptr);
|
||||
|
@ -90,7 +98,8 @@ int main()
|
|||
::free_message(dst);
|
||||
::free_identity(bob);
|
||||
::free_identity(alice);
|
||||
::release(session);
|
||||
|
||||
pEp::Adapter::session(pEp::Adapter::release);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "Adapter.hh"
|
||||
#include "passphrase_cache.hh"
|
||||
#include "status_to_string.hh"
|
||||
|
||||
|
@ -21,10 +23,14 @@ extern "C" {
|
|||
|
||||
int main()
|
||||
{
|
||||
PEP_SESSION session;
|
||||
PEP_STATUS status = ::init(&session, NULL, NULL);
|
||||
assert(status == PEP_STATUS_OK);
|
||||
assert(session);
|
||||
char path[MAXPATHLEN+1];
|
||||
const char *templ = "/tmp/test_passphrase_cache.XXXXXXXXXXXX";
|
||||
strcpy(path, templ);
|
||||
char *tmpdir = mkdtemp(path);
|
||||
assert(tmpdir);
|
||||
chdir(tmpdir);
|
||||
setenv("HOME", path, 1);
|
||||
std::cerr << "test directory: " << path << std::endl;
|
||||
|
||||
const char *str = "23";
|
||||
char *bytes = NULL;
|
||||
|
@ -45,9 +51,9 @@ int main()
|
|||
std::cout << "expected: two passphrases but reverse order\n";
|
||||
cache.for_each_passphrase([&](std::string passphrase){std::cout << "'" << passphrase << "'\n"; return false;});
|
||||
|
||||
status = cache.api(api_test1, session, "23", bytes, n, (::stringlist_t *) NULL);
|
||||
PEP_STATUS status = cache.api(api_test1, pEp::Adapter::session(), "23", bytes, n, (::stringlist_t *) NULL);
|
||||
assert(status == PEP_WRONG_PASSPHRASE);
|
||||
status = cache.api(api_test2, session, n, str, bytes, sl);
|
||||
status = cache.api(api_test2, pEp::Adapter::session(), n, str, bytes, sl);
|
||||
assert(status == PEP_STATUS_OK);
|
||||
|
||||
cache.add("hello");
|
||||
|
@ -74,12 +80,12 @@ int main()
|
|||
std::cout << "expected: no passphrase\n";
|
||||
cache.for_each_passphrase([&](std::string passphrase){std::cout << "'" << passphrase << "'\n"; return false;});
|
||||
|
||||
status = cache.api(api_test1, session, str, bytes, n, sl);
|
||||
status = cache.api(api_test1, pEp::Adapter::session(), str, bytes, n, sl);
|
||||
assert(status == PEP_WRONG_PASSPHRASE);
|
||||
status = cache.api(api_test2, session, 23, str, bytes, sl);
|
||||
status = cache.api(api_test2, pEp::Adapter::session(), 23, str, bytes, sl);
|
||||
assert(status == PEP_STATUS_OK);
|
||||
|
||||
::release(session);
|
||||
pEp::Adapter::session(pEp::Adapter::release);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue