diff --git a/test/framework.cc b/test/framework.cc index de3a76e..52f0191 100644 --- a/test/framework.cc +++ b/test/framework.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -10,23 +11,45 @@ #include #include -#include "Adapter.hh" namespace pEp { namespace Test { using namespace Adapter; - void setup() + void setup(vector& a) { + string dir = "/tmp/test_pEp.XXXXXXXXXXXX"; + + if (a.size() > 1) { + if (a[1] == "--help") { + cout << "usage: " << a[0] << " [--dir TESTDIR]" << endl; + exit(0); + } + else if (a[1] == "--dir" && a.size() == 3) { + dir = a[2]; + } + else { + cerr << "illegal parameter" << endl; + exit(1); + } + } + char path[MAXPATHLEN+1]; - const char *templ = "/tmp/test_pEp.XXXXXXXXXXXX"; + const char *templ = dir.c_str(); strcpy(path, templ); - char *tmpdir = mkdtemp(path); - assert(tmpdir); - chdir(tmpdir); + mkdtemp(path); + chdir(path); setenv("HOME", path, 1); cerr << "test directory: " << path << endl; - + } + + void setup(int argc, char **argv) + { + vector a{(size_t) argc}; + for (int i=0; i +#include + #include "Adapter.hh" namespace pEp { namespace Test { using namespace std; - void setup(); + void setup(vector& a); + void setup(int argc=1, char **argv=nullptr); void import_key_from_file(string filename); }; }; diff --git a/test/test_ensure_passphrase.cc b/test/test_ensure_passphrase.cc index f0e48ee..b096c1f 100644 --- a/test/test_ensure_passphrase.cc +++ b/test/test_ensure_passphrase.cc @@ -20,9 +20,9 @@ using namespace pEp; using namespace pEp::Adapter; using namespace std; -int main() +int main(int argc, char **argv) { - Test::setup(); + Test::setup(argc, argv); passphrase_cache.add("erwin"); passphrase_cache.add("cathy");