From 0426b8b8bb2543bb53a8a5d5d437b183640a7db5 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Wed, 12 Aug 2020 22:46:05 +0200 Subject: [PATCH] documenting test framework --- Makefile | 14 +------- Makefile.conf | 12 +++---- test/Makefile | 6 ++++ test/framework.cc | 86 +++++++++++++++++++++++++++++++++++++++-------- test/framework.hh | 33 +++++++++++++++++- 5 files changed, 116 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index 1014831..ffe12d8 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/Makefile.conf b/Makefile.conf index 793b57d..29a61ab 100644 --- a/Makefile.conf +++ b/Makefile.conf @@ -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 ######### diff --git a/test/Makefile b/test/Makefile index b45fab6..cdd2435 100644 --- a/test/Makefile +++ b/test/Makefile @@ -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.* + diff --git a/test/framework.cc b/test/framework.cc index ea8f672..33dfe3e 100644 --- a/test/framework.cc +++ b/test/framework.cc @@ -4,29 +4,44 @@ #include #include #include +#include #include #include #include #include #include +#include #include +#include + +pEp::Test::Transport pEp::Test::transport; +std::string pEp::Test::path; namespace pEp { namespace Test { using namespace Adapter; - void setup(vector& a) + void setup(vector& 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 a{(size_t) argc}; + vector args{(size_t) argc}; for (int i=0; i(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); + + } }; }; diff --git a/test/framework.hh b/test/framework.hh index 065d691..ddb8fb7 100644 --- a/test/framework.hh +++ b/test/framework.hh @@ -2,6 +2,7 @@ #include #include +#include #include "Adapter.hh" @@ -9,9 +10,39 @@ namespace pEp { namespace Test { using namespace std; - void setup(vector& a); + // manually set up test + void setup(vector& 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; }; };