support command line

pull/1/head
Volker Birk 3 years ago
parent 155e8c26a8
commit f724aac37c

@ -3,6 +3,7 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <unistd.h>
#include <assert.h>
#include <stdlib.h>
@ -10,23 +11,45 @@
#include <sys/param.h>
#include <pEp/keymanagement.h>
#include "Adapter.hh"
namespace pEp {
namespace Test {
using namespace Adapter;
void setup()
void setup(vector<string>& 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<string> a{(size_t) argc};
for (int i=0; i<argc; ++i)
a[i] = argv[i];
setup(a);
}
void import_key_from_file(string filename)

@ -1,13 +1,16 @@
#pragma once
#include <string>
#include <vector>
#include "Adapter.hh"
namespace pEp {
namespace Test {
using namespace std;
void setup();
void setup(vector<string>& a);
void setup(int argc=1, char **argv=nullptr);
void import_key_from_file(string filename);
};
};

@ -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");

Loading…
Cancel
Save