Browse Source

Blob.toString() enhanced with plain data output.

Added Tests for addAttachment() / getAttachments()
Nonfunctional change, to_blob() now used in to_bloblist()
JNI-86
heck 2 years ago
parent
commit
c72a677c81
4 changed files with 50 additions and 42 deletions
  1. +1
    -1
      src/foundation/pEp/jniadapter/Blob.java
  2. +4
    -26
      src/jniutils.cc
  3. +9
    -9
      test/Basic/SyncCallbacks.java
  4. +36
    -6
      test/Basic/Testing.java

+ 1
- 1
src/foundation/pEp/jniadapter/Blob.java View File

@ -20,7 +20,7 @@ public class Blob {
String ret = "";
ret += "mime_type: \"" + mime_type + "\"\n";
ret += "filename: \"" + filename + "\"\n";
ret += "data plain: \"" + data + "\"\n";
ret += "data plain: \"" + AbstractEngine.toUTF16(data) + "\"\n";
ret += "data decoded: \"" + _b.dataToXER() + "\"\n";
return ret;
}


+ 4
- 26
src/jniutils.cc View File

@ -1,5 +1,4 @@
#include "jniutils.hh"
#include <stdexcept>
#include <typeinfo>
#include <time.h>
@ -670,7 +669,6 @@ namespace pEp {
}
// TODO: Use to_blob() inside the loop
bloblist_t *to_bloblist(JNIEnv *env, jobject obj)
{
if (!obj)
@ -680,35 +678,15 @@ namespace pEp {
if (size == 0)
return NULL;
static const char *classname = "foundation/pEp/jniadapter/_Blob";
jclass clazz = findClass(env, classname);
jfieldID data_id = getFieldID(env, classname, "data", "[B");
bloblist_t *bl = new_bloblist(NULL, 0, NULL, NULL);
bloblist_t *_bl;
_bl = bl;
jint i;
for (_bl = bl, i = 0; i < (int) size; i++) {
for (i = 0; i < (int) size; i++) {
jobject o = callObjectMethod(env, obj, "get", i);
char *mime_type = _getStringField(env, classname, o,
"mime_type");
char *filename = _getStringField(env, classname, o,
"filename");
jbyteArray _data =
reinterpret_cast<jbyteArray>(env->GetObjectField(o,
data_id));
size_t size = (size_t) env->GetArrayLength(_data);
char *b = (char *) malloc(size);
assert(b);
env->GetByteArrayRegion(_data, 0, size, (jbyte*)b);
_bl = bloblist_add(_bl, b, size, mime_type, filename);
bloblist_t *b = to_blob(env, o);
_bl = bloblist_add(_bl, b->value, b->size, b->mime_type, b->filename);
env->DeleteLocalRef(o);
free(mime_type);
free(filename);
}
return bl;


+ 9
- 9
test/Basic/SyncCallbacks.java View File

@ -3,23 +3,23 @@ import foundation.pEp.jniadapter.*;
class SyncCallbacks implements Sync.MessageToSendCallback, Sync.NotifyHandshakeCallback {
public void messageToSend(Message message)
{
System.out.println("================================");
System.out.println("Message to send called");
System.out.println("================================");
System.out.println("Message to send called");
System.out.println("From: " + message.getFrom());
System.out.println("To: " + message.getTo());
System.out.println("Subject: " + message.getShortmsg());
System.out.println("Attachement[0]: " + message.getAttachments().get(0).toString());
System.out.println("================================");
System.out.println("================================");
}
public void notifyHandshake(Identity myself, Identity partner, SyncHandshakeSignal signal)
{
System.out.println("================================");
System.out.println("Notify handshake called");
System.out.println("Myself: " + myself);
System.out.println("Partner: " + partner);
System.out.println("Signal: " + signal);
System.out.println("================================");
System.out.println("================================");
System.out.println("Notify handshake called");
System.out.println("Myself: " + myself);
System.out.println("Partner: " + partner);
System.out.println("Signal: " + signal);
System.out.println("================================");
}
}

+ 36
- 6
test/Basic/Testing.java View File

@ -17,7 +17,7 @@ class Testing {
URL[] urls = ((URLClassLoader)cl).getURLs();
for(URL url: urls){
System.out.println(url.getFile());
System.out.println(url.getFile());
}
}
@ -83,6 +83,24 @@ class Testing {
msg.setLongmsg("this is a test");
msg.setDir(Message.Direction.Outgoing);
// Test setAttachements() with nrAttachemnts
int nrAttachemnts = 3;
{
System.out.print("Adding " + String.valueOf(nrAttachemnts) + " attachements [");
Vector<Blob> attachments = new Vector<>();
for (int i = 0; i < nrAttachemnts; i++) {
Blob blb = new Blob();
String dataString = "Attachement nr: " + String.valueOf(i) + " [TEST DATA]";
blb.data = dataString.getBytes();
blb.filename = "testfilename.txt";
attachments.add(blb);
System.out.print(".");
}
msg.setAttachments(attachments);
System.out.println("]");
}
Message enc = null;
try {
enc = e.encrypt_message(msg, null, Message.EncFormat.PEP);
@ -94,11 +112,7 @@ class Testing {
}
System.out.println(enc.getLongmsg());
Vector<Blob> attachments = enc.getAttachments();
// Print msg.txt (encrypted body) contents.
System.out.println(e.toUTF16(attachments.get(1).data));
msg.setDir(Message.Direction.Outgoing);
try {
System.out.println("Rating preview: " + e.outgoing_message_rating_preview(msg));
System.out.println("Rating" + e.outgoing_message_rating(msg));
@ -117,8 +131,24 @@ class Testing {
ex.printStackTrace();
}
System.out.println(result.dst.getShortmsg());
System.out.println(result.dst.getLongmsg());
// Test getAttachments()
{
Vector<Blob> attachments = result.dst.getAttachments();
System.out.println("get attachement data");
System.out.println("Attachement count: " + String.valueOf(attachments.size()));
for( Blob a: attachments) {
System.out.println("Attachement nr: " + String.valueOf(attachments.indexOf(a)));
System.out.println("[");
System.out.println(a.toString());
System.out.println("]");
}
}
System.out.println("TEST DONE - FINISHED");
try {
@ -126,7 +156,7 @@ class Testing {
}
catch (pEpException ex) {
System.out.println("cannot reset all own keys");
ex.printStackTrace();
ex.printStackTrace();
}
System.out.println("Testing.java: e.StartSync()");


Loading…
Cancel
Save