Browse Source

more android tests, more fixes. Still, to_stringpairlist crash.

JNI-44
Edouard Tisserant 6 years ago
parent
commit
a9d26e8eee
4 changed files with 256 additions and 30 deletions
  1. +204
    -5
      androidTests/app/src/main/java/com/pep/k9/MainActivity.java
  2. +49
    -23
      src/gen_java_Message.ysl2
  3. +1
    -0
      src/jniutils.cc
  4. +2
    -2
      src/org/pEp/jniadapter/Pair.java

+ 204
- 5
androidTests/app/src/main/java/com/pep/k9/MainActivity.java View File

@ -14,7 +14,9 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Vector;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
@ -46,8 +48,8 @@ public class MainActivity extends AppCompatActivity {
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
try {
testPEpAliceBobJohn();
//testPEpTypes();
//testPEpAliceBobJohn();
testPEpTypes();
}
catch (Exception ex) {
Log.e("PEPTEST", "##################### TEST Exception ####################",ex);
@ -58,7 +60,7 @@ public class MainActivity extends AppCompatActivity {
return super.onOptionsItemSelected(item);
}
private String LoadAssetAsString(String fname) throws IOException {
private byte[] LoadAssetAsBuffer(String fname) throws IOException {
AssetManager assetManager = getAssets();
InputStream input;
@ -69,9 +71,14 @@ public class MainActivity extends AppCompatActivity {
input.read(buffer);
input.close();
// byte buffer into a string
return new String(buffer);
// byte buffer
return buffer;
}
private String LoadAssetAsString(String fname) throws IOException {
// byte buffer into a string
return new String(LoadAssetAsBuffer(fname));
}
public void testPEpTypes() throws pEpException, IOException {
@ -83,6 +90,8 @@ public class MainActivity extends AppCompatActivity {
Message msg = new Message();
// Note : this looks like some target code, ins't it ?
// Call getter before call to getter
assert msg.getDir()==null;
assert msg.getId()==null;
@ -104,6 +113,196 @@ public class MainActivity extends AppCompatActivity {
assert msg.getOptFields()==null;
assert msg.getEncFormat()==null;
// Call setter with non-null and check getter returns the same
msg.setDir(Message.Direction.Outgoing);
assert msg.getDir()==Message.Direction.Outgoing;
msg.setId("1234ID");
assert msg.getId().equals("1234ID");
msg.setShortmsg("ShrtMsg");
assert msg.getLongmsg().equals("ShrtMsg");
msg.setLongmsg("Loooooooooooooonger Message");
assert msg.getLongmsg().equals("Loooooooooooooonger Message");
msg.setLongmsgFormatted("<html/>");
assert msg.getLongmsgFormatted().equals("<html/>");
{
Vector<Blob> attachments = new Vector<Blob>();
Blob blb = new Blob();
blb.data = LoadAssetAsBuffer("0xC9C2EE39.asc");
blb.filename = "0xC9C2EE39.asc";
attachments.add(blb);
msg.setAttachments(attachments);
Vector<Blob> detach = msg.getAttachments();
Blob dblb = detach.firstElement();
assert dblb.filename.equals(blb.filename);
assert dblb.data.equals(blb.data);
}
{
Date now = new Date();
msg.setSent(now);
assert msg.getSent().equals(now);
}
{
Date now = new Date();
msg.setRecv(now);
assert msg.getRecv().equals(now);
}
{
Identity alice = new Identity();
alice.username = "Alice Test";
alice.address = "pep.test.alice@pep-project.org";
alice.user_id = "111";
alice.me = true;
alice.fpr = null;
msg.setFrom(alice);
Identity _alice = msg.getFrom();
assert _alice.username.equals("Alice Test");
assert _alice.address.equals("pep.test.alice@pep-project.org");
assert _alice.user_id.equals("111");
assert _alice.me == true;
assert _alice.fpr == null;
}
{
Vector<Identity> rcpts = new Vector<Identity>();
Identity alice = new Identity();
alice.username = "Alice Test";
alice.address = "pep.test.alice@pep-project.org";
alice.user_id = "111";
alice.me = true;
alice.fpr = null;
rcpts.add(alice);
msg.setTo(rcpts);
Vector<Identity> _rcpts = msg.getTo();
Identity _alice = _rcpts.firstElement();
assert _alice.username.equals("Alice Test");
assert _alice.address.equals("pep.test.alice@pep-project.org");
assert _alice.user_id.equals("111");
assert _alice.me == true;
assert _alice.fpr == null;
}
{
Identity alice = new Identity();
alice.username = "Alice Test";
alice.address = "pep.test.alice@pep-project.org";
alice.user_id = "111";
alice.me = true;
alice.fpr = null;
msg.setRecvBy(alice);
Identity _alice = msg.getRecvBy();
assert _alice.username.equals("Alice Test");
assert _alice.address.equals("pep.test.alice@pep-project.org");
assert _alice.user_id.equals("111");
assert _alice.me == true;
assert _alice.fpr == null;
}
{
Vector<Identity> rcpts = new Vector<Identity>();
Identity alice = new Identity();
alice.username = "Alice Test";
alice.address = "pep.test.alice@pep-project.org";
alice.user_id = "111";
alice.me = true;
alice.fpr = null;
rcpts.add(alice);
msg.setCc(rcpts);
Vector<Identity> _rcpts = msg.getCc();
Identity _alice = _rcpts.firstElement();
assert _alice.username.equals("Alice Test");
assert _alice.address.equals("pep.test.alice@pep-project.org");
assert _alice.user_id.equals("111");
assert _alice.me == true;
assert _alice.fpr == null;
}
{
Vector<Identity> rcpts = new Vector<Identity>();
Identity alice = new Identity();
alice.username = "Alice Test";
alice.address = "pep.test.alice@pep-project.org";
alice.user_id = "111";
alice.me = true;
alice.fpr = null;
rcpts.add(alice);
msg.setBcc(rcpts);
Vector<Identity> _rcpts = msg.getBcc();
Identity _alice = _rcpts.firstElement();
assert _alice.username.equals("Alice Test");
assert _alice.address.equals("pep.test.alice@pep-project.org");
assert _alice.user_id.equals("111");
assert _alice.me == true;
assert _alice.fpr == null;
}
{
Vector<String> strvec = new Vector<String>();
strvec.add("Blub");
msg.setInReplyTo(strvec);
Vector<String> _strvec = msg.getInReplyTo();
assert _strvec.firstElement().equals("Blub");
}
{
Vector<String> strvec = new Vector<String>();
strvec.add("Blub");
msg.setReferences(strvec);
Vector<String> _strvec = msg.getReferences();
assert _strvec.firstElement().equals("Blub");
}
{
Vector<String> strvec = new Vector<String>();
strvec.add("Blub");
msg.setKeywords(strvec);
Vector<String> _strvec = msg.getKeywords();
assert _strvec.firstElement().equals("Blub");
}
msg.setComments("No comment.");
assert msg.getComments().equals("No comment.");
{
ArrayList<Pair<String, String>> pairs = new ArrayList<Pair<String, String>>();
Pair<String,String> pair = new Pair<String,String>("left","right");
pairs.add(pair);
msg.setOptFields(pairs);
ArrayList<Pair<String, String>> _pairs = msg.getOptFields();
Pair<String,String> _pair = _pairs.get(0);
assert _pair.first.equals("left");
assert _pair.second.equals("right");
}
msg.setEncFormat(Message.EncFormat.PEP);
assert msg.getEncFormat()==Message.EncFormat.PEP;
// Call setter with null call to getter
msg.setDir(null);
assert msg.getDir()==null;


+ 49
- 23
src/gen_java_Message.ysl2 View File

@ -107,36 +107,62 @@ tstylesheet {
||
when "$ctype = 'identitylist' or $ctype = 'bloblist'"
||
`` const "ename", "substring-before(substring-after($type, '<'), '>')";
private native «$itype» _get«$name»();
private native void _set«$name»(«$itype» value);
public «$type» get«$name»() {
«$type» list = new «$type»();
for (_«$ename» i : _get«$name»())
list.add(new «$ename»(i));
return list;
}
public void set«$name»(«$type» value) {
if(value != null){
«$itype» list = new «$itype»();
for («$ename» i : value)
list.add(new _«$ename»(i));
_set«$name»(list);
}else{
_set«$name»(null);
when "$ctype = 'identitylist' or $ctype = 'bloblist' or $ctype = 'stringlist' or $ctype = 'stringpairlist'"
{
const "ename", "substring-after(substring($type,1,string-length($type)-1), '<')";
const "iename" choose {
when "$ctype = 'stringlist'" > byte[]
when "$ctype = 'stringpairlist'" > Pair<byte[],byte[]>
otherwise > _«$ename»
}
const "convget" choose {
when "$ctype = 'stringlist'" > AbstractEngine.toUTF16(i)
when "$ctype = 'stringpairlist'" > new Pair<String, String>(AbstractEngine.toUTF16(i.first), AbstractEngine.toUTF16(i.second))
otherwise > new «$ename»(i)
}
const "convset" choose {
when "$ctype = 'stringlist'" > AbstractEngine.toUTF8(i)
when "$ctype = 'stringpairlist'" > new Pair<byte[],byte[]>(AbstractEngine.toUTF8(i.first), AbstractEngine.toUTF8(i.second))
otherwise > new _«$ename»(i)
}
||
private native «$itype» _get«$name»();
private native void _set«$name»(«$itype» value);
public «$type» get«$name»() {
«$itype» glist = _get«$name»();
if(glist != null){
«$type» list = new «$type»();
for («$iename» i : glist)
list.add(«$convget»);
return list;
}
return null;
}
public void set«$name»(«$type» value) {
if(value != null){
«$itype» list = new «$itype»();
for («$ename» i : value)
list.add(«$convset»);
_set«$name»(list);
}else{
_set«$name»(null);
}
}
||
}
||
when "$itype != $type"
||
private native «$itype» _get«$name»();
private native void _set«$name»(«$itype» value);
public «$type» get«$name»() {
return AbstractEngine.toUTF16(_get«$name»());
«$itype» res = _get«$name»();
if(res != null)
return AbstractEngine.toUTF16(res);
else
return null;
}
public void set«$name»(«$type» value) {
if(value != null)


+ 1
- 0
src/jniutils.cc View File

@ -273,6 +273,7 @@ namespace pEp {
stringpair_list_t *sl = new_stringpair_list(NULL);
stringpair_list_t *_sl;
jint i;
for (_sl = sl, i = 0; i < (int) size; i++) {
jobject pair = callObjectMethod(env, obj, "get", i);
jbyteArray first =


+ 2
- 2
src/org/pEp/jniadapter/Pair.java View File

@ -4,9 +4,9 @@ public class Pair<F, S> {
public F first;
public S second;
Pair() { }
public Pair() { }
Pair(F f, S s) {
public Pair(F f, S s) {
first = f;
second = s;
}


Loading…
Cancel
Save