documenting test framework

pull/1/head
Volker Birk 3 years ago
parent d40633d0f1
commit 0426b8b8bb

@ -7,19 +7,7 @@ include Makefile.conf
TARGET=libpEpAdapter.a
ifneq ($(wildcard local.conf),)
$(info ================================================)
$(info Overrides in `local.conf` are used.)
$(info ================================================)
endif
ifdef BUILD_CONFIG
$(info ================================================)
$(info Overrides in `$(BUILD_CONFIG)` are used.)
$(info ================================================)
endif
.PHONY: all, lib, test, install, uninstall, clean
.PHONY: install, uninstall, clean
SOURCE=$(wildcard *.cc)
HEADERS=$(wildcard *.hh *.hxx)

@ -7,7 +7,7 @@ HERE:=$(dir $(lastword $(MAKEFILE_LIST)))
PREFIX?=$(HOME)
CXXFLAGS+=-std=c++11 -fPIC -O0
CXXFLAGS+=-std=c++11 -fPIC
# Build target
BUILD_FOR:=$(shell uname)
@ -19,13 +19,11 @@ else ifneq (,$(findstring clang,$(CXX)))
endif
# Debug or Release build
DEBUG=1
ifeq ($(DEBUG),1)
$(info Debug build (set DEBUG=0 for release build))
CXXFLAGS+=-g
ifndef NDEBUG
CXXFLAGS+=-g -O0
else
$(info Release Build (set DEBUG=1 for debug build))
CXXFLAGS+=-DNDEBUG=1
CXXFLAGS+=-DNDEBUG -O2
endif
######### Engine #########

@ -11,8 +11,14 @@ all: $(TST)
$(TST): framework.o
.PHONY: clean rmtestdata
clean:
rm -f $(TST)
rm -Rf *.dSYM
rm -f *.o
rm -Rf /tmp/test_pEp.*
rmtestdata:
rm -Rf /tmp/test_pEp.*

@ -4,29 +4,44 @@
#include <fstream>
#include <sstream>
#include <utility>
#include <exception>
#include <unistd.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <pEp/keymanagement.h>
#include <pEp/mime.h>
pEp::Test::Transport pEp::Test::transport;
std::string pEp::Test::path;
namespace pEp {
namespace Test {
using namespace Adapter;
void setup(vector<string>& a)
void setup(vector<string>& args)
{
#ifdef WIN32
string dir = getenv("TEMP");
dir += "\\test_pEp.XXXXXXXXXXXX";
#else
string dir = "/tmp/test_pEp.XXXXXXXXXXXX";
#endif
if (a.size() > 1) {
if (a[1] == "--help") {
cout << "usage: " << a[0] << " [--dir HOME]" << endl;
if (args.size() > 1) {
if (args[1] == "--help") {
#ifdef WIN32
cout << "usage: " << args[0] << " [--dir LOCALAPPDATA]" << endl;
#else
cout << "usage: " << args[0] << " [--dir HOME]" << endl;
#endif
exit(0);
}
else if (a[1] == "--dir" && a.size() == 3) {
dir = a[2];
else if (args[1] == "--dir" && args.size() == 3) {
dir = args[2];
}
else {
cerr << "illegal parameter" << endl;
@ -34,22 +49,27 @@ namespace pEp {
}
}
char path[MAXPATHLEN+1];
char _path[MAXPATHLEN+1];
const char *templ = dir.c_str();
strcpy(path, templ);
mkdtemp(path);
chdir(path);
setenv("HOME", path, 1);
strcpy(_path, templ);
mkdtemp(_path);
chdir(_path);
#ifdef WIN32
setenv("LOCALAPPDATA", _path, 1);
#else
setenv("HOME", _path, 1);
#endif
path = _path;
cerr << "test directory: " << path << endl;
}
void setup(int argc, char **argv)
{
vector<string> a{(size_t) argc};
vector<string> args{(size_t) argc};
for (int i=0; i<argc; ++i)
a[i] = argv[i];
args[i] = argv[i];
setup(a);
setup(args);
}
void import_key_from_file(string filename)
@ -61,5 +81,43 @@ namespace pEp {
assert(status == PEP_KEY_IMPORTED);
::free_identity_list(il);
}
Message make_message(::message *msg)
{
return shared_ptr<::message>(msg, ::free_message);
}
Message make_message(string text)
{
::message *msg;
bool has_possible_pEp_msg;
PEP_STATUS status = ::mime_decode_message(text.c_str(), text.length(), &msg, &has_possible_pEp_msg);
throw_status(status);
return make_message(msg);
}
string make_string(Message msg)
{
char *mimetext;
PEP_STATUS status = ::mime_encode_message(msg.get(), false, &mimetext, false);
throw_status(status);
string text = mimetext;
free(mimetext);
return text;
}
Message Transport::recv()
{
mkdir(inbox_path.c_str(), 0770);
auto msg = make_message(nullptr);
return msg;
}
void Transport::send(Message msg)
{
mkdir(outbox_path.c_str(), 0770);
}
};
};

@ -2,6 +2,7 @@
#include <string>
#include <vector>
#include <memory>
#include "Adapter.hh"
@ -9,9 +10,39 @@ namespace pEp {
namespace Test {
using namespace std;
void setup(vector<string>& a);
// manually set up test
void setup(vector<string>& args);
// call this in main() for auto set up
void setup(int argc=1, char **argv=nullptr);
void import_key_from_file(string filename);
using Message = shared_ptr<::message>;
// use this instead of constructor to auto assign ::free_message as
// deleter
Message make_message(::message *msg);
// MIME parser
Message make_message(string text);
// MIME composer
string make_string(Message msg);
struct Transport {
string inbox_path = "inbox";
string outbox_path = "outbox";
// reads next message from inbox
Message recv();
// appends message to outbox
void send(Message msg);
};
extern Transport transport;
extern string path;
};
};

Loading…
Cancel
Save