Browse Source

More tests, more fixes.

JNI-44
Edouard Tisserant 10 years ago
parent
commit
1a1ece32b1
  1. 37
      androidTests/app/src/main/java/com/pep/k9/MainActivity.java
  2. 6
      src/org/pEp/jniadapter/AbstractEngine.java

37
androidTests/app/src/main/java/com/pep/k9/MainActivity.java

@ -48,8 +48,8 @@ public class MainActivity extends AppCompatActivity {
//noinspection SimplifiableIfStatement //noinspection SimplifiableIfStatement
if (id == R.id.action_settings) { if (id == R.id.action_settings) {
try { try {
//testPEpAliceBobJohn(); testPEpAliceBobJohn();
testPEpTypes(); //testPEpTypes();
} }
catch (Exception ex) { catch (Exception ex) {
Log.e("PEPTEST", "##################### TEST Exception ####################",ex); Log.e("PEPTEST", "##################### TEST Exception ####################",ex);
@ -426,34 +426,37 @@ public class MainActivity extends AppCompatActivity {
Vector<Identity> to = new Vector<Identity>(); Vector<Identity> to = new Vector<Identity>();
to.add(bob); to.add(bob);
to.add(john);
msg.setTo(to); msg.setTo(to);
Vector<Identity> cc = new Vector<Identity>();
cc.add(alice);
msg.setCc(cc);
Vector<Identity> bcc = new Vector<Identity>();
bcc.add(john);
msg.setBcc(bcc);
msg.setShortmsg("hello, world"); msg.setShortmsg("hello, world");
msg.setLongmsg("this is a test"); msg.setLongmsg("this is a test");
msg.setDir(Message.Direction.Outgoing); msg.setDir(Message.Direction.Outgoing);
Log.d("PEPTEST", e.outgoing_message_color(msg).toString()); assert e.outgoing_message_color(msg).equals(Color.pEpRatingReliable);
Message enc = null; Message enc = null;
enc = e.encrypt_message(msg, null); enc = e.encrypt_message(msg, null);
if(enc != null) { assert enc != null;
Log.d("PEPTEST", "encrypted OK");
Log.d("PEPTEST", enc.getLongmsg());
Vector<Blob> attachments = enc.getAttachments();
Log.d("PEPTEST", e.toUTF16(attachments.get(1).data));
Engine.decrypt_message_Return result = null; assert enc.getShortmsg().equals("pEp");
result = e.decrypt_message(enc); assert enc.getLongmsg().contains("pep-project.org");
Log.d("PEPTEST", "decrypted");
Log.d("PEPTEST", result.dst.getShortmsg()); Vector<Blob> attachments = enc.getAttachments();
Log.d("PEPTEST", result.dst.getLongmsg()); assert e.toUTF16(attachments.get(1).data).startsWith("-----BEGIN PGP MESSAGE-----");
} else {
Log.d("PEPTEST", "NOT encrypted !!!");
} Engine.decrypt_message_Return result = null;
result = e.decrypt_message(enc);
assert result.dst.getShortmsg().equals("hello, world");
assert result.dst.getLongmsg().equals("this is a test");
} }

6
src/org/pEp/jniadapter/AbstractEngine.java

@ -39,7 +39,11 @@ abstract class AbstractEngine implements AutoCloseable {
try { try {
String _str = Normalizer.normalize(str, Normalizer.Form.NFC); String _str = Normalizer.normalize(str, Normalizer.Form.NFC);
return _str.getBytes("UTF-8"); byte _buf[] = _str.getBytes("UTF-8");
// F*ck you, Java !
byte _cpy[] = new byte[_buf.length];
System.arraycopy(_buf,0,_cpy,0,_buf.length);
return _cpy;
} }
catch (UnsupportedEncodingException e) { catch (UnsupportedEncodingException e) {
assert false; assert false;

Loading…
Cancel
Save