diff --git a/test/java/foundation/pEp/jniadapter/test/jni134/TestAlice.java b/test/java/foundation/pEp/jniadapter/test/jni134/TestAlice.java index 5de6710..7e47440 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni134/TestAlice.java +++ b/test/java/foundation/pEp/jniadapter/test/jni134/TestAlice.java @@ -3,14 +3,19 @@ package foundation.pEp.jniadapter.test.jni134; import foundation.pEp.jniadapter.Blob; import foundation.pEp.jniadapter.Identity; import foundation.pEp.jniadapter.Message; +import foundation.pEp.jniadapter.Pair; import foundation.pEp.jniadapter.test.utils.AdapterBaseTestContext; +import foundation.pEp.jniadapter.test.utils.AdapterTestUtils; import foundation.pEp.pitytest.TestSuite; import foundation.pEp.pitytest.TestUnit; import foundation.pEp.pitytest.utils.TestUtils; +import java.util.ArrayList; import java.util.Date; import java.util.Vector; +import static foundation.pEp.pitytest.TestLogger.log; + class Jni134TestContext extends AdapterBaseTestContext { @Override public AdapterBaseTestContext init() throws Throwable { @@ -66,26 +71,32 @@ class TestAlice { assert outVal.equals(inVal) : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; }); + // TODO: use .equals() new TestUnit("setAttachments() == getAttachments() ", new Jni134TestContext(), ctx -> { Message msg = new Message(); Vector inVal = ctx.attachments; msg.setAttachments(inVal); Vector outVal = msg.getAttachments(); - for (int i = 0; i < 3; i++) { + for (int i = 0; i < ctx.attachmentsLen; i++) { Blob inElem = inVal.get(i); Blob outElem = outVal.get(i); - assert inElem == inElem : "\nreturned '" + outElem + "' instead of '" + inElem + "'"; + assert inElem == outElem : "\nreturned '" + outElem + "' instead of '" + inElem + "'"; } }); + // TODO: Date precision is truncated to seconds in the message struct new TestUnit("setSent() == getSent() ", new Jni134TestContext(), ctx -> { Message msg = new Message(); Date inVal = new Date(); msg.setSent(inVal); Date outVal = msg.getSent(); - assert outVal == inVal : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; + log("EPOCH: " + Long.toString(inVal.getTime())); + log("EPOCH: " + Long.toString(inVal.toInstant().getEpochSecond())); + log("EPOCH: " + Long.toString(outVal.getTime())); + assert outVal.equals(inVal) : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; }); + // TODO: Date precision is truncated to seconds in the message struct new TestUnit("setRecv() == getRecv() ", new Jni134TestContext(), ctx -> { Message msg = new Message(); Date inVal = new Date(); @@ -94,12 +105,154 @@ class TestAlice { assert outVal == inVal : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; }); + // TODO: use .equals() new TestUnit("setFrom() == getFrom() ", new Jni134TestContext(), ctx -> { Message msg = new Message(); Identity inVal = ctx.alice; msg.setFrom(inVal); Identity outVal = msg.getFrom(); - assert outVal.equals(inVal) : "\nreturned '" + outVal + "'\nexpected '" + inVal + "'"; + assert outVal.equals(inVal) : "\nreturned:\n'" + outVal + "'\nexpected:\n'" + inVal + "'"; + }); + + // TODO: use .equals() + new TestUnit("setTo() == getTo() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + Vector inVal = new Vector(); + inVal.add(ctx.alice); + inVal.add(ctx.bob); + msg.setTo(inVal); + Vector outVal = msg.getTo(); + for (int i = 0; i < 2; i++) { + Identity inElem = inVal.get(i); + Identity outElem = outVal.get(i); + assert outElem.equals(inElem) : "\nreturned:\n '" + outElem + "'\nexpected:\n '" + inElem + "'"; + } + }); + + // TODO: use .equals() + new TestUnit("setRecvBy() == getRecvBy() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + Identity inVal = ctx.alice; + msg.setRecvBy(inVal); + Identity outVal = msg.getRecvBy(); + assert outVal.equals(inVal) : "\nreturned:\n '" + outVal + "'\nexpected:\n '" + inVal + "'"; + }); + + // TODO: use .equals() + new TestUnit("setCc() == getCc() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + Vector inVal = new Vector(); + inVal.add(ctx.alice); + inVal.add(ctx.bob); + msg.setCc(inVal); + Vector outVal = msg.getCc(); + for (int i = 0; i < 2; i++) { + Identity inElem = inVal.get(i); + Identity outElem = outVal.get(i); + assert outElem.equals(inElem) : "\nreturned:\n '" + outElem + "'\nexpected:\n '" + inElem + "'"; + } + }); + + // TODO: use .equals() + new TestUnit("setBcc() == getBcc() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + Vector inVal = new Vector(); + inVal.add(ctx.alice); + inVal.add(ctx.bob); + msg.setCc(inVal); + Vector outVal = msg.getBcc(); + for (int i = 0; i < 2; i++) { + Identity inElem = inVal.get(i); + Identity outElem = outVal.get(i); + assert outElem.equals(inElem) : "\nreturned:\n '" + outElem + "'\nexpected:\n '" + inElem + "'"; + } + }); + + // TODO: use .equals() + new TestUnit("setReplyTo() == getReplyTo() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + Vector inVal = new Vector(); + inVal.add(ctx.alice); + inVal.add(ctx.bob); + msg.setReplyTo(inVal); + Vector outVal = msg.getReplyTo(); + for (int i = 0; i < 2; i++) { + Identity inElem = inVal.get(i); + Identity outElem = outVal.get(i); + assert outElem.equals(inElem) : "\nreturned:\n '" + outElem + "'\nexpected:\n '" + inElem + "'"; + } + }); + + // TODO: use .equals() + new TestUnit("setInReplyTo() == getInReplyTo() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + Vector inVal = new Vector(); + inVal.add("pEp-auto-consume@pEp.foundation"); + inVal.add("any_other_message_id@blabla.bubu"); + msg.setInReplyTo(inVal); + Vector outVal = msg.getInReplyTo(); + for (int i = 0; i < 2; i++) { + String inElem = inVal.get(i); + String outElem = outVal.get(i); + assert outElem.equals(inElem) : "\nreturned:\n '" + outElem + "'\nexpected:\n '" + inElem + "'"; + } + }); + + // TODO: use .equals() + new TestUnit("setReferences() == getReferences() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + Vector inVal = new Vector(); + inVal.add("pEp-auto-consume@pEp.foundation"); + inVal.add("any_other_message_id@blabla.bubu"); + msg.setReferences(inVal); + Vector outVal = msg.getReferences(); + for (int i = 0; i < 2; i++) { + String inElem = inVal.get(i); + String outElem = outVal.get(i); + assert outElem.equals(inElem) : "\nreturned:\n '" + outElem + "'\nexpected:\n '" + inElem + "'"; + } + }); + + // TODO: use .equals() + new TestUnit("setKeywords() == getKeywords() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + Vector inVal = new Vector(); + inVal.add("pEp-auto-consume@pEp.foundation"); + inVal.add("any_other_message_id@blabla.bubu"); + msg.setKeywords(inVal); + Vector outVal = msg.getKeywords(); + for (int i = 0; i < 2; i++) { + String inElem = inVal.get(i); + String outElem = outVal.get(i); + assert outElem.equals(inElem) : "\nreturned:\n '" + outElem + "'\nexpected:\n '" + inElem + "'"; + } + }); + + // TODO: use .equals() + new TestUnit("setComments() == getComments() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + String inVal = "pEp-auto-consume@pEp.foundation"; + msg.setComments(inVal); + String outVal = msg.getComments(); + assert outVal.equals(inVal) : "\nreturned:\n '" + outVal + "'\nexpected:\n '" + inVal + "'"; + }); + + new TestUnit("setOptFields() == getOptFields() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + ArrayList> inVal = new ArrayList<>(); + inVal.add(new Pair<>("Received", "in time")); + inVal.add(new Pair<>("X-Foobaz", "of course")); + msg.setOptFields(inVal); + ArrayList> outVal = msg.getOptFields(); + assert AdapterTestUtils.optFieldsEqual(inVal, outVal) : "\nreturned:\n '" + outVal + "'\nexpected:\n '" + inVal + "'"; + }); + + new TestUnit("setEncFormat() == getEncFormat() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + Message.EncFormat inVal = Message.EncFormat.PEP; + msg.setEncFormat(inVal); + Message.EncFormat outVal = msg.getEncFormat(); + assert inVal == outVal : "\nreturned:\n '" + outVal + "'\nexpected:\n '" + inVal + "'"; }); TestSuite.getDefault().run();