diff --git a/test/java/foundation/pEp/jniadapter/test/jni135/Makefile b/test/java/foundation/pEp/jniadapter/test/jni135/Makefile new file mode 100644 index 0000000..2298b54 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/jni135/Makefile @@ -0,0 +1,37 @@ + include ../../../../../../../Makefile.conf +include ../Makefile.conf + +TEST_UNIT_NAME=jni135 + +JAVA_CLASSES = \ + TestAlice.class \ + ../utils/AdapterBaseTestContext.class \ + ../utils/AdapterTestUtils.class \ + ../utils/TestCallbacks.class + +.PHONY: pitytest compile alice test clean + +all: alice compile + +pitytest: + $(MAKE) -C $(PITYTEST_DIR) + +alice: compile clean-pep-home-alice + cd $(JAVA_CWD);pwd;HOME=$(JAVA_PEP_HOME_DIR_ALICE) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestAlice + +compile: $(JAVA_CLASSES) pitytest + +%.class: %.java + cd $(JAVA_CWD);javac -cp $(CLASSPATH) $(JAVA_PKG_BASEPATH)/$(TEST_UNIT_NAME)/$< + +clean: + rm -f $(JAVA_CLASSES) + rm -f *.class + rm -f *.log + rm -Rf .gnupg + rm -Rf .lldb + +clean-pep-home: clean-pep-home-alice + +clean-pep-home-alice: + rm -rf $(PEP_HOME_DIR_ALICE)/.pEp diff --git a/test/java/foundation/pEp/jniadapter/test/jni135/TestAlice.java b/test/java/foundation/pEp/jniadapter/test/jni135/TestAlice.java new file mode 100644 index 0000000..bc6ef98 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/jni135/TestAlice.java @@ -0,0 +1,87 @@ +package foundation.pEp.jniadapter.test.jni135; + +import foundation.pEp.jniadapter.Blob; +import foundation.pEp.jniadapter.Message; +import foundation.pEp.jniadapter.decrypt_message_Return; +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.lang.ref.WeakReference; +import java.util.Arrays; +import java.util.Vector; + +import static foundation.pEp.pitytest.TestLogger.log; +import static foundation.pEp.pitytest.TestLogger.logH2; + +class Jni135TestContext extends AdapterBaseTestContext { + @Override + public AdapterBaseTestContext init() throws Throwable { + super.init(); + return this; + } +} + +class TestAlice { + public static void gc() { +// log("gc start"); + Object obj = new Object(); + WeakReference ref = new WeakReference(obj); + obj = null; + while (ref.get() != null) { + System.gc(); + } +// log("gc end"); + } + + public static void main(String[] args) throws Exception { + TestSuite.getDefault().setVerbose(true); + TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN); +// TestUtils.readKey(); + AdapterBaseTestContext jni135Ctx = new Jni135TestContext(); + + new TestUnit("setDir() == getDir() ", new Jni135TestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + ctx.bob = ctx.engine.myself(ctx.bob); + + while (true) { + Message msg1Plain = AdapterTestUtils.makeNewTestMessage(ctx.alice, ctx.bob, Message.Direction.Outgoing); + Blob bigBlob = AdapterTestUtils.makeNewTestBlob(100000, "atti1", "text/plain"); + Vector atts = new Vector(); + atts.add(bigBlob); + msg1Plain.setAttachments(atts); + +// log(new String(bigBlob.data)); + logH2("msg plain", TestUtils.TermColor.CYAN); + log(AdapterTestUtils.msgToString(msg1Plain, false)); +// log("plain: " + msg1Plain.getId()); + Message msg1Enc = ctx.engine.encrypt_message(msg1Plain, null, Message.EncFormat.PEP); + +// logH2("msg encrypted", TestUtils.TermColor.CYAN); +// log(AdapterTestUtils.msgToString(msg1Enc, false)); +// log("encrypted: " + msg1Enc.getId()); + + decrypt_message_Return decRet = ctx.engine.decrypt_message(msg1Enc, null, 0); + assert decRet != null : "could not decrypt message"; + if (decRet != null) { + logH2("msg decrypted", TestUtils.TermColor.CYAN); + log(AdapterTestUtils.msgToString(decRet.dst, false)); +// log("decrypted: " + decRet.dst.getId()); +// assert new String(decRet.dst.getAttachments().get(0).data).equals(new String(bigBlob.data)) : "attachments decrypted dont equal original"; + assert decRet.dst.getLongmsg().equals(msg1Plain.getLongmsg()) : "attachments decrypted dont equal original"; + } + + msg1Plain = null; + msg1Enc = null; + decRet = null; + gc(); + } + }); + + TestSuite.getDefault().run(); + } +} + +