Browse Source

Added attchements test, fixed asserts, now testing for real

JNI-44
Edouard Tisserant 10 years ago
parent
commit
e034a62c2d
  1. BIN
      androidTests/app/assets/pep.png
  2. BIN
      androidTests/app/assets/spinner.gif
  3. BIN
      androidTests/app/assets/yml2.tar.bz2
  4. 254
      androidTests/app/src/main/java/com/pep/k9/MainActivity.java

BIN
androidTests/app/assets/pep.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
androidTests/app/assets/spinner.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

BIN
androidTests/app/assets/yml2.tar.bz2

Binary file not shown.

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

@ -15,6 +15,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Vector; import java.util.Vector;
import java.util.Date; import java.util.Date;
@ -48,8 +49,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);
@ -80,7 +81,7 @@ public class MainActivity extends AppCompatActivity {
// byte buffer into a string // byte buffer into a string
return new String(LoadAssetAsBuffer(fname)); return new String(LoadAssetAsBuffer(fname));
} }
public void testPEpTypes() throws pEpException, IOException { public void testPEpTypes() throws pEpException, IOException, AssertionError {
Engine e; Engine e;
@ -93,41 +94,41 @@ public class MainActivity extends AppCompatActivity {
// Note : this looks like some target code, ins't it ? // Note : this looks like some target code, ins't it ?
// Call getter before call to getter // Call getter before call to getter
assert msg.getDir()==null; if(!(msg.getDir()==null)) throw new AssertionError();
assert msg.getId()==null; if(!(msg.getId()==null)) throw new AssertionError();
assert msg.getLongmsg()==null; if(!(msg.getLongmsg()==null)) throw new AssertionError();
assert msg.getLongmsg()==null; if(!(msg.getLongmsgFormatted()==null)) throw new AssertionError();
assert msg.getLongmsgFormatted()==null; if(!(msg.getAttachments()==null)) throw new AssertionError();
assert msg.getAttachments()==null; if(!(msg.getSent()==null)) throw new AssertionError();
assert msg.getSent()==null; if(!(msg.getRecv()==null)) throw new AssertionError();
assert msg.getRecv()==null; if(!(msg.getFrom()==null)) throw new AssertionError();
assert msg.getFrom()==null; if(!(msg.getTo()==null)) throw new AssertionError();
assert msg.getTo()==null; if(!(msg.getRecvBy()==null)) throw new AssertionError();
assert msg.getRecvBy()==null; if(!(msg.getCc()==null)) throw new AssertionError();
assert msg.getCc()==null; if(!(msg.getBcc()==null)) throw new AssertionError();
assert msg.getBcc()==null; if(!(msg.getInReplyTo()==null)) throw new AssertionError();
assert msg.getInReplyTo()==null; if(!(msg.getReferences()==null)) throw new AssertionError();
assert msg.getReferences()==null; if(!(msg.getKeywords()==null)) throw new AssertionError();
assert msg.getKeywords()==null; if(!(msg.getComments()==null)) throw new AssertionError();
assert msg.getComments()==null; if(!(msg.getOptFields()==null)) throw new AssertionError();
assert msg.getOptFields()==null; if(!(msg.getEncFormat()==null)) throw new AssertionError();
assert msg.getEncFormat()==null;
// Call setter with non-null and check getter returns the same // Call setter with non-null and check getter returns the same
msg.setDir(Message.Direction.Outgoing); msg.setDir(Message.Direction.Outgoing);
assert msg.getDir()==Message.Direction.Outgoing; if(!(msg.getDir()==Message.Direction.Outgoing)) throw new AssertionError();
msg.setId("1234ID"); msg.setId("1234ID");
assert msg.getId().equals("1234ID"); if(!(msg.getId().equals("1234ID"))) throw new AssertionError();
msg.setShortmsg("ShrtMsg"); msg.setShortmsg("ShrtMsg");
assert msg.getLongmsg().equals("ShrtMsg"); if(!(msg.getShortmsg().equals("ShrtMsg"))) throw new AssertionError();
msg.setLongmsg("Loooooooooooooonger Message"); msg.setLongmsg("Loooooooooooooonger Message");
assert msg.getLongmsg().equals("Loooooooooooooonger Message"); if(!(msg.getLongmsg().equals("Loooooooooooooonger Message"))) throw new AssertionError();
msg.setLongmsgFormatted("<html/>"); msg.setLongmsgFormatted("<html/>");
assert msg.getLongmsgFormatted().equals("<html/>"); if(!(msg.getLongmsgFormatted().equals("<html/>"))) throw new AssertionError();
{ {
Vector<Blob> attachments = new Vector<Blob>(); Vector<Blob> attachments = new Vector<Blob>();
@ -138,22 +139,23 @@ public class MainActivity extends AppCompatActivity {
msg.setAttachments(attachments); msg.setAttachments(attachments);
Vector<Blob> detach = msg.getAttachments(); Vector<Blob> detach = msg.getAttachments();
Blob dblb = detach.firstElement(); Blob dblb = detach.firstElement();
assert dblb.filename.equals(blb.filename); if(!(dblb.filename.equals(blb.filename))) throw new AssertionError();
assert dblb.data.equals(blb.data); if(!(Arrays.equals(dblb.data, blb.data))) throw new AssertionError();
} }
{ {
Date now = new Date(); Date now = new Date();
msg.setSent(now); msg.setSent(now);
assert msg.getSent().equals(now); Date res = msg.getSent();
if(!(res.equals(now))) throw new AssertionError();
} }
{ {
Date now = new Date(); Date now = new Date();
msg.setRecv(now); msg.setRecv(now);
assert msg.getRecv().equals(now); if(!(msg.getRecv().equals(now))) throw new AssertionError();
} }
{ {
@ -167,11 +169,11 @@ public class MainActivity extends AppCompatActivity {
msg.setFrom(alice); msg.setFrom(alice);
Identity _alice = msg.getFrom(); Identity _alice = msg.getFrom();
assert _alice.username.equals("Alice Test"); if(!(_alice.username.equals("Alice Test"))) throw new AssertionError();
assert _alice.address.equals("pep.test.alice@pep-project.org"); if(!(_alice.address.equals("pep.test.alice@pep-project.org"))) throw new AssertionError();
assert _alice.user_id.equals("111"); if(!(_alice.user_id.equals("111"))) throw new AssertionError();
assert _alice.me == true; if(!(_alice.me == true)) throw new AssertionError();
assert _alice.fpr == null; if(!(_alice.fpr == null)) throw new AssertionError();
} }
{ {
@ -188,11 +190,11 @@ public class MainActivity extends AppCompatActivity {
Vector<Identity> _rcpts = msg.getTo(); Vector<Identity> _rcpts = msg.getTo();
Identity _alice = _rcpts.firstElement(); Identity _alice = _rcpts.firstElement();
assert _alice.username.equals("Alice Test"); if(!(_alice.username.equals("Alice Test"))) throw new AssertionError();
assert _alice.address.equals("pep.test.alice@pep-project.org"); if(!(_alice.address.equals("pep.test.alice@pep-project.org"))) throw new AssertionError();
assert _alice.user_id.equals("111"); if(!(_alice.user_id.equals("111"))) throw new AssertionError();
assert _alice.me == true; if(!(_alice.me == true)) throw new AssertionError();
assert _alice.fpr == null; if(!(_alice.fpr == null)) throw new AssertionError();
} }
{ {
@ -206,11 +208,11 @@ public class MainActivity extends AppCompatActivity {
msg.setRecvBy(alice); msg.setRecvBy(alice);
Identity _alice = msg.getRecvBy(); Identity _alice = msg.getRecvBy();
assert _alice.username.equals("Alice Test"); if(!(_alice.username.equals("Alice Test"))) throw new AssertionError();
assert _alice.address.equals("pep.test.alice@pep-project.org"); if(!(_alice.address.equals("pep.test.alice@pep-project.org"))) throw new AssertionError();
assert _alice.user_id.equals("111"); if(!(_alice.user_id.equals("111"))) throw new AssertionError();
assert _alice.me == true; if(!(_alice.me == true)) throw new AssertionError();
assert _alice.fpr == null; if(!(_alice.fpr == null)) throw new AssertionError();
} }
{ {
@ -227,11 +229,11 @@ public class MainActivity extends AppCompatActivity {
Vector<Identity> _rcpts = msg.getCc(); Vector<Identity> _rcpts = msg.getCc();
Identity _alice = _rcpts.firstElement(); Identity _alice = _rcpts.firstElement();
assert _alice.username.equals("Alice Test"); if(!(_alice.username.equals("Alice Test"))) throw new AssertionError();
assert _alice.address.equals("pep.test.alice@pep-project.org"); if(!(_alice.address.equals("pep.test.alice@pep-project.org"))) throw new AssertionError();
assert _alice.user_id.equals("111"); if(!(_alice.user_id.equals("111"))) throw new AssertionError();
assert _alice.me == true; if(!(_alice.me == true)) throw new AssertionError();
assert _alice.fpr == null; if(!(_alice.fpr == null)) throw new AssertionError();
} }
{ {
@ -248,11 +250,11 @@ public class MainActivity extends AppCompatActivity {
Vector<Identity> _rcpts = msg.getBcc(); Vector<Identity> _rcpts = msg.getBcc();
Identity _alice = _rcpts.firstElement(); Identity _alice = _rcpts.firstElement();
assert _alice.username.equals("Alice Test"); if(!(_alice.username.equals("Alice Test"))) throw new AssertionError();
assert _alice.address.equals("pep.test.alice@pep-project.org"); if(!(_alice.address.equals("pep.test.alice@pep-project.org"))) throw new AssertionError();
assert _alice.user_id.equals("111"); if(!(_alice.user_id.equals("111"))) throw new AssertionError();
assert _alice.me == true; if(!(_alice.me == true)) throw new AssertionError();
assert _alice.fpr == null; if(!(_alice.fpr == null)) throw new AssertionError();
} }
{ {
@ -262,7 +264,7 @@ public class MainActivity extends AppCompatActivity {
msg.setInReplyTo(strvec); msg.setInReplyTo(strvec);
Vector<String> _strvec = msg.getInReplyTo(); Vector<String> _strvec = msg.getInReplyTo();
assert _strvec.firstElement().equals("Blub"); if(!(_strvec.firstElement().equals("Blub"))) throw new AssertionError();
} }
{ {
@ -272,7 +274,7 @@ public class MainActivity extends AppCompatActivity {
msg.setReferences(strvec); msg.setReferences(strvec);
Vector<String> _strvec = msg.getReferences(); Vector<String> _strvec = msg.getReferences();
assert _strvec.firstElement().equals("Blub"); if(!(_strvec.firstElement().equals("Blub"))) throw new AssertionError();
} }
{ {
@ -282,11 +284,11 @@ public class MainActivity extends AppCompatActivity {
msg.setKeywords(strvec); msg.setKeywords(strvec);
Vector<String> _strvec = msg.getKeywords(); Vector<String> _strvec = msg.getKeywords();
assert _strvec.firstElement().equals("Blub"); if(!(_strvec.firstElement().equals("Blub"))) throw new AssertionError();
} }
msg.setComments("No comment."); msg.setComments("No comment.");
assert msg.getComments().equals("No comment."); if(!(msg.getComments().equals("No comment."))) throw new AssertionError();
{ {
ArrayList<Pair<String, String>> pairs = new ArrayList<Pair<String, String>>(); ArrayList<Pair<String, String>> pairs = new ArrayList<Pair<String, String>>();
@ -296,75 +298,75 @@ public class MainActivity extends AppCompatActivity {
msg.setOptFields(pairs); msg.setOptFields(pairs);
ArrayList<Pair<String, String>> _pairs = msg.getOptFields(); ArrayList<Pair<String, String>> _pairs = msg.getOptFields();
Pair<String,String> _pair = _pairs.get(0); Pair<String,String> _pair = _pairs.get(0);
assert _pair.first.equals("left"); if(!(_pair.first.equals("left"))) throw new AssertionError();
assert _pair.second.equals("right"); if(!(_pair.second.equals("right"))) throw new AssertionError();
} }
msg.setEncFormat(Message.EncFormat.PEP); msg.setEncFormat(Message.EncFormat.PEP);
assert msg.getEncFormat()==Message.EncFormat.PEP; if(!(msg.getEncFormat()==Message.EncFormat.PEP)) throw new AssertionError();
// Call setter with null call to getter // Call setter with null call to getter
msg.setDir(null); msg.setDir(null);
assert msg.getDir()==null; if(!(msg.getDir()==null)) throw new AssertionError();
msg.setId(null); msg.setId(null);
assert msg.getId()==null; if(!(msg.getId()==null)) throw new AssertionError();
msg.setShortmsg(null); msg.setShortmsg(null);
assert msg.getLongmsg()==null; if(!(msg.getLongmsg()==null)) throw new AssertionError();
msg.setLongmsg(null); msg.setLongmsg(null);
assert msg.getLongmsg()==null; if(!(msg.getLongmsg()==null)) throw new AssertionError();
msg.setLongmsgFormatted(null); msg.setLongmsgFormatted(null);
assert msg.getLongmsgFormatted()==null; if(!(msg.getLongmsgFormatted()==null)) throw new AssertionError();
msg.setAttachments(null); msg.setAttachments(null);
assert msg.getAttachments()==null; if(!(msg.getAttachments()==null)) throw new AssertionError();
msg.setSent(null); msg.setSent(null);
assert msg.getSent()==null; if(!(msg.getSent()==null)) throw new AssertionError();
msg.setRecv(null); msg.setRecv(null);
assert msg.getRecv()==null; if(!(msg.getRecv()==null)) throw new AssertionError();
msg.setFrom(null); msg.setFrom(null);
assert msg.getFrom()==null; if(!(msg.getFrom()==null)) throw new AssertionError();
msg.setTo(null); msg.setTo(null);
assert msg.getTo()==null; if(!(msg.getTo()==null)) throw new AssertionError();
msg.setRecvBy(null); msg.setRecvBy(null);
assert msg.getRecvBy()==null; if(!(msg.getRecvBy()==null)) throw new AssertionError();
msg.setCc(null); msg.setCc(null);
assert msg.getCc()==null; if(!(msg.getCc()==null)) throw new AssertionError();
msg.setBcc(null); msg.setBcc(null);
assert msg.getBcc()==null; if(!(msg.getBcc()==null)) throw new AssertionError();
msg.setInReplyTo(null); msg.setInReplyTo(null);
assert msg.getInReplyTo()==null; if(!(msg.getInReplyTo()==null)) throw new AssertionError();
msg.setReferences(null); msg.setReferences(null);
assert msg.getReferences()==null; if(!(msg.getReferences()==null)) throw new AssertionError();
msg.setKeywords(null); msg.setKeywords(null);
assert msg.getKeywords()==null; if(!(msg.getKeywords()==null)) throw new AssertionError();
msg.setComments(null); msg.setComments(null);
assert msg.getComments()==null; if(!(msg.getComments()==null)) throw new AssertionError();
msg.setOptFields(null); msg.setOptFields(null);
assert msg.getOptFields()==null; if(!(msg.getOptFields()==null)) throw new AssertionError();
msg.setEncFormat(null); msg.setEncFormat(null);
assert msg.getEncFormat()==null; if(!(msg.getEncFormat()==null)) throw new AssertionError();
Log.d("PEPTEST", "Test finished"); Log.d("PEPTEST", "Test finished");
} }
public void testPEpAliceBobJohn() throws pEpException, IOException { public void testPEpAliceBobJohn() throws pEpException, IOException, AssertionError {
Engine e; Engine e;
// load // load
@ -447,42 +449,90 @@ public class MainActivity extends AppCompatActivity {
msg.setOptFields(pairs); msg.setOptFields(pairs);
} }
byte[] gif = LoadAssetAsBuffer("spinner.gif");
byte[] png = LoadAssetAsBuffer("pep.png");
byte[] tbz = LoadAssetAsBuffer("yml2.tar.bz2");
{
Vector<Blob> attachments = new Vector<Blob>();
{
Blob b = new Blob();
b.data = png;
b.filename = "pep.png";
b.mime_type = "image/png";
attachments.add(b);
}
{
Blob b = new Blob();
b.data = gif;
b.filename = "spinner.gif";
b.mime_type = "image/png";
attachments.add(b);
}
{
Blob b = new Blob();
b.data = tbz;
b.filename = "yml.tar.bz2";
b.mime_type = "application/x-gtar";
attachments.add(b);
}
msg.setAttachments(attachments);
}
msg.setDir(Message.Direction.Outgoing); msg.setDir(Message.Direction.Outgoing);
assert e.outgoing_message_color(msg).equals(Color.pEpRatingReliable); if(!(e.outgoing_message_color(msg).equals(Color.pEpRatingReliable))) throw new AssertionError();
Message enc = null; Message enc = null;
enc = e.encrypt_message(msg, null); enc = e.encrypt_message(msg, null);
assert enc != null; if(!(enc != null)) throw new AssertionError();
assert enc.getShortmsg().equals("pEp"); if(!(enc.getShortmsg().equals("pEp"))) throw new AssertionError();
assert enc.getLongmsg().contains("pep-project.org"); if(!(enc.getLongmsg().contains("pep-project.org"))) throw new AssertionError();
Vector<Blob> attachments = enc.getAttachments(); Vector<Blob> attachments = enc.getAttachments();
assert e.toUTF16(attachments.get(1).data).startsWith("-----BEGIN PGP MESSAGE-----"); if(!(e.toUTF16(attachments.get(1).data).startsWith("-----BEGIN PGP MESSAGE-----"))) throw new AssertionError();
Engine.decrypt_message_Return result = null; Engine.decrypt_message_Return result = null;
result = e.decrypt_message(enc); result = e.decrypt_message(enc);
assert result.dst.getShortmsg().equals("hello, world"); if(!(result.dst.getShortmsg().equals("hello, world"))) throw new AssertionError();
assert result.dst.getLongmsg().equals("this is a test"); if(!(result.dst.getLongmsg().equals("this is a test"))) throw new AssertionError();
ArrayList<Pair<String, String>> _pairs = result.dst.getOptFields(); ArrayList<Pair<String, String>> _pairs = result.dst.getOptFields();
/* FIXME ?
{ {
String fbz = null; byte msk = 0;
String rcvd = null;
for (Pair<String, String> _pair : _pairs) { for (Pair<String, String> _pair : _pairs) {
if (_pair.first.equals("Received")) if (_pair.first.equals("Received")) {
rcvd = _pair.second; if(!(_pair.second.equals("in time"))) throw new AssertionError();
if (_pair.first.equals("X-Foobaz")) msk |= 1;
fbz = _pair.second; }else if (_pair.first.equals("X-Foobaz")) {
if(!(_pair.second.equals("of course"))) throw new AssertionError();
msk |= 2;
}
} }
/* FIXME ? if(!(msk == 3)) throw new AssertionError();
assert rcvd!=null && rcvd.equals("in time");
assert fbz!=null && fbz.equals("of course");
*/
} }
*/
{
Vector<Blob> detach = msg.getAttachments();
byte msk = 0;
for (Blob dblb : detach) {
if (dblb.filename.equals("pep.png")) {
if(!(dblb.data.equals(png))) throw new AssertionError();
if(!(dblb.mime_type.equals("image/png"))) throw new AssertionError();
msk |= 1;
}else if (dblb.filename.equals("spinner.gif")) {
if(!(dblb.data.equals(gif))) throw new AssertionError();
if(!(dblb.mime_type.equals("image/gif"))) throw new AssertionError();
msk |= 2;
}else if (dblb.filename.equals("yml2.tar.bz2")) {
if(!(dblb.data.equals(tbz))) throw new AssertionError();
if(!(dblb.mime_type.equals("application/x-gtar"))) throw new AssertionError();
msk |= 4;
}
}
if(!(msk == 7)) throw new AssertionError();
}
} }
} }

Loading…
Cancel
Save