test framework

pull/1/head
Volker Birk 3 years ago
parent 6cb9c7ed5d
commit 9da3fa4339

@ -43,13 +43,14 @@ lib: $(TARGET)
all: lib
test: lib
$(MAKE) -C test all
$(MAKE) -C test
$(TARGET): $(OBJECTS)
$(AR) -rc $@ $^
clean:
rm -vf $(TARGET) $(OBJECTS) $(DEPENDS)
rm -f *.d.*
$(MAKE) -C test clean
install: $(TARGET)

@ -9,8 +9,9 @@ TST=$(subst .cc,,$(SRC))
all: $(TST)
%: %.cc ../libpEpAdapter.a
$(TST): framework.o
clean:
rm -f $(TST)
rm -Rf *.dSYM
rm -f *.o

@ -0,0 +1,42 @@
#include "framework.hh"
#include <iostream>
#include <fstream>
#include <sstream>
#include <unistd.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <pEp/keymanagement.h>
#include "Adapter.hh"
namespace pEp {
namespace Test {
using namespace Adapter;
void setup()
{
char path[MAXPATHLEN+1];
const char *templ = "/tmp/test_pEp.XXXXXXXXXXXX";
strcpy(path, templ);
char *tmpdir = mkdtemp(path);
assert(tmpdir);
chdir(tmpdir);
setenv("HOME", path, 1);
cerr << "test directory: " << path << endl;
}
void import_key_from_file(string filename)
{
ifstream f(filename, ifstream::in);
string key{istreambuf_iterator<char>(f), istreambuf_iterator<char>()};
::identity_list *il = NULL;
PEP_STATUS status = ::import_key(session(), key.c_str(), key.length(), &il);
assert(status == PEP_KEY_IMPORTED);
::free_identity_list(il);
}
};
};

@ -0,0 +1,14 @@
#pragma once
#include <string>
#include "Adapter.hh"
namespace pEp {
namespace Test {
using namespace std;
void setup();
void import_key_from_file(string filename);
};
};

@ -1,7 +1,7 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#include "Adapter.hh"
#include "framework.hh"
#include <iostream>
#include <assert.h>
#include <unistd.h>
@ -26,14 +26,7 @@ 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;
pEp::Test::setup();
// Create new identity
pEpLog("updating or creating identity for me");

@ -1,7 +1,7 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#include "Adapter.hh"
#include "framework.hh"
#include <iostream>
#include <assert.h>
#include <unistd.h>
@ -32,6 +32,8 @@ public:
} o;
int main() {
pEp::Test::setup();
// 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");

@ -7,7 +7,8 @@
#include <string.h>
#include <sys/param.h>
#include "Adapter.hh"
#include "framework.hh"
#include "passphrase_cache.hh"
#include "status_to_string.hh"
@ -19,18 +20,10 @@ using namespace pEp;
using namespace pEp::Adapter;
using namespace std;
void import_key_from_file(string filename)
int main()
{
ifstream f(filename, ifstream::in);
string key{istreambuf_iterator<char>(f), istreambuf_iterator<char>()};
::identity_list *il = NULL;
PEP_STATUS status = ::import_key(session(), key.c_str(), key.length(), &il);
assert(status == PEP_KEY_IMPORTED);
::free_identity_list(il);
}
Test::setup();
void test()
{
passphrase_cache.add("erwin");
passphrase_cache.add("cathy");
passphrase_cache.add("bob");
@ -41,8 +34,8 @@ void test()
const char* erwin_filename = ENGINE_TEST "/test_keys/erwin_normal_encrypted.pgp";
const char* erwin_fpr = "CBA968BC01FCEB89F04CCF155C5E9E3F0420A570";
import_key_from_file(bob_filename);
import_key_from_file(erwin_filename);
Test::import_key_from_file(bob_filename);
Test::import_key_from_file(erwin_filename);
pEp_identity* bob = ::new_identity("bob@example.org", bob_fpr, "BOB", "Bob Dog");
PEP_STATUS status = ::set_own_key(session(), bob, bob_fpr);
@ -59,20 +52,7 @@ void test()
::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;
}

@ -3,21 +3,14 @@
#include <sys/param.h>
#include <unistd.h>
#include "message_cache.hh"
#include "Adapter.hh"
#include "framework.hh"
using namespace std;
using namespace pEp;
int main()
{
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;
Test::setup();
pEp_identity *alice = ::new_identity("alice@mail.com", nullptr, PEP_OWN_USERID, "Alice");
::myself(pEp::Adapter::session(), alice);

@ -3,7 +3,7 @@
#include <assert.h>
#include <sys/param.h>
#include "Adapter.hh"
#include "framework.hh"
#include "passphrase_cache.hh"
#include "status_to_string.hh"
@ -23,14 +23,7 @@ extern "C" {
int main()
{
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;
pEp::Test::setup();
const char *str = "23";
char *bytes = NULL;

Loading…
Cancel
Save