Browse Source

test framework

pull/1/head
Volker Birk 1 year ago
parent
commit
9da3fa4339
9 changed files with 75 additions and 56 deletions
  1. +2
    -1
      Makefile
  2. +2
    -1
      test/Makefile
  3. +42
    -0
      test/framework.cc
  4. +14
    -0
      test/framework.hh
  5. +2
    -9
      test/test_adapter.cc
  6. +3
    -1
      test/test_adapter_cxx.cc
  7. +6
    -26
      test/test_ensure_passphrase.cc
  8. +2
    -9
      test/test_message_cache.cc
  9. +2
    -9
      test/test_passphrase_cache.cc

+ 2
- 1
Makefile View File

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


+ 2
- 1
test/Makefile View File

@ -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

+ 42
- 0
test/framework.cc View File

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

+ 14
- 0
test/framework.hh View File

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

+ 2
- 9
test/test_adapter.cc View File

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


+ 3
- 1
test/test_adapter_cxx.cc View File

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


+ 6
- 26
test/test_ensure_passphrase.cc View File

@ -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;
}

+ 2
- 9
test/test_message_cache.cc View File

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


+ 2
- 9
test/test_passphrase_cache.cc View File

@ -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