adding a test for the message_cache

ENGINE-781
Volker Birk 2 years ago
parent 4e1d2c2b59
commit 7da016627d
  1. 5
      message_cache.cc
  2. 4
      message_cache.hh
  3. 4
      test/Makefile
  4. 61
      test/test_message_cache.cc

@ -1,6 +1,6 @@
#include "message_cache.hh"
pEp::MessageCache message_cache;
pEp::MessageCache pEp::message_cache;
namespace pEp {
DYNAMIC_API PEP_STATUS MessageCache::cache_decrypt_message(
@ -144,6 +144,7 @@ namespace pEp {
throw std::bad_alloc();
dst->id = dup(src->id);
dst->shortmsg = dup(src->shortmsg);
if (!emptystr(src->longmsg))
@ -198,7 +199,7 @@ namespace pEp {
::message *_cpy = empty_message_copy(src);
::message *_src;
::message *_src = (::message *) malloc(sizeof(::message));
::memcpy(_src, src, sizeof(::message));
::memcpy(src, _cpy, sizeof(::message));

@ -11,10 +11,6 @@ namespace pEp {
struct cache_entry {
cache_entry(::message *s, ::message *d)
: src(s), dst(d) { }
~cache_entry() {
::free_message(src);
::free_message(dst);
};
::message *src;
::message *dst;

@ -6,7 +6,7 @@ CXXFLAGS+=-I../
.PHONY=all, test_adapter, test_adapter_cxx, test_library
all: test_adapter test_adapter_cxx test_library test_passphrase_cache test_semaphore
all: test_adapter test_adapter_cxx test_library test_passphrase_cache test_semaphore test_message_cache
test_adapter: test_adapter.cc ../libpEpAdapter.a
@ -18,6 +18,8 @@ test_passphrase_cache: test_passphrase_cache.cc ../libpEpAdapter.a
test_semaphore: test_semaphore.cc ../libpEpAdapter.a
test_message_cache: test_message_cache.cc ../libpEpAdapter.a
clean:
rm -vf test_adapter
rm -rvf test_adapter.dSYM

@ -0,0 +1,61 @@
#include <iostream>
#include <cassert>
#include "message_cache.hh"
using namespace std;
using namespace pEp;
int main()
{
PEP_SESSION session;
PEP_STATUS status = ::init(&session, nullptr, nullptr);
assert(status == PEP_STATUS_OK);
pEp_identity *alice = ::new_identity("alice@mail.com", nullptr, PEP_OWN_USERID, "Alice");
::myself(session, alice);
pEp_identity *bob = ::new_identity("bob@mail.com", nullptr, PEP_OWN_USERID, "Bob");
::update_identity(session, bob);
::message *src = new_message(PEP_dir_incoming);
src->from = identity_dup(alice);
src->to = ::new_identity_list(::identity_dup(bob));
src->shortmsg = strdup("short message");
assert(src->shortmsg);
src->longmsg = strdup("long message");
assert(src->longmsg);
src->longmsg_formatted = strdup("<long msg='formatted'/>");
assert(src->longmsg_formatted);
src->attachments = new_bloblist(strdup("blobdata"), 8, "application/octet-stream", "blob.data");
assert(src->attachments && src->attachments->value);
::message *dst = nullptr;
PEP_rating rating;
PEP_decrypt_flags_t flags = 0;
stringlist_t *keylist = nullptr;
status = MessageCache::cache_decrypt_message(session, src, &dst, &keylist, &rating, &flags);
assert(status == PEP_ILLEGAL_VALUE);
src->id = strdup("42");
assert(src->id);
status = MessageCache::cache_decrypt_message(session, src, &dst, &keylist, &rating, &flags);
assert(status != PEP_ILLEGAL_VALUE);
assert(string(src->longmsg) == "pEp");
assert(src->attachments == nullptr);
cout << status << endl;
::free_message(src);
::free_message(dst);
::free_identity(bob);
::free_identity(alice);
::release(session);
return 0;
}
Loading…
Cancel
Save