diff --git a/test/JNI_85/Makefile b/test/JNI_85/Makefile new file mode 100644 index 0000000..733c3eb --- /dev/null +++ b/test/JNI_85/Makefile @@ -0,0 +1,26 @@ +include ../../Makefile.conf + +#TODO: Remove when successufuly reproduce the error, and then use it to avoid regression +$(info This is to be run using pEpJNIAdapter 626) + + +CLASSPATH=.:../../src +VM=java -Xcheck:jni -Djava.library.path=../../src +#VM=lldb java -- -Xcheck:jni -Djava.library.path=../src + +.PHONY: test clean + +test: SyncCallbacks.class Step1.class Step2.class + -HOME=$(PWD) CLASSPATH=$(CLASSPATH) time $(VM) Step1 + HOME=$(PWD) CLASSPATH=$(CLASSPATH) time $(VM) Step2 + +%.class: %.java + CLASSPATH=$(CLASSPATH) javac $< + +clean: + rm -f *.class + rm -f *.log + rm -f .pEp_* + rm -Rf .pEp + rm -Rf .gnupg + rm -Rf .lldb diff --git a/test/JNI_85/Step1.java b/test/JNI_85/Step1.java new file mode 100644 index 0000000..d41fa74 --- /dev/null +++ b/test/JNI_85/Step1.java @@ -0,0 +1,57 @@ +import foundation.pEp.jniadapter.*; +import java.util.Vector; +import java.net.URL; +import java.net.URLClassLoader; +import java.lang.Thread; +import java.lang.InterruptedException; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +class Step1 { + + public static void main(String[] args) { + new Thread(() -> { + Engine e = null; + + // load + try { + e = new Engine(); + SyncCallbacks callbacks = new SyncCallbacks(); + //e.setNotifyHandshakeCallback(callbacks); + e.setMessageToSendCallback(callbacks); + } + catch (pEpException ex) { + System.out.println("Cannot load"); + System.exit(-1); + } + System.out.println("Test loaded"); + + + // Keygen + Engine en = new Engine(); + System.out.println("Generating keys: "); + Identity user2 = new Identity(); + user2.user_id = "pEp_own_userId"; + user2.me = true; + user2.username = "Test User 2"; + user2.address = "jniTestUser2@peptest.ch"; + user2 = en.myself(user2); + System.out.print("Keys generated: "); + System.out.println(user2.fpr); + + // it's not necessary - you can just shutdown Sync and that's it + // but for this test give sync a chance to process all messages + try { + Thread.sleep(200); + System.out.println("End wait"); + } + catch (InterruptedException ex) { } + + }).start(); + + throw new RuntimeException(); + } +} diff --git a/test/JNI_85/Step2.java b/test/JNI_85/Step2.java new file mode 100644 index 0000000..388d217 --- /dev/null +++ b/test/JNI_85/Step2.java @@ -0,0 +1,43 @@ +import foundation.pEp.jniadapter.*; +import java.util.Vector; +import java.net.URL; +import java.net.URLClassLoader; +import java.lang.Thread; +import java.lang.InterruptedException; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +class Step2 { + + public static void main(String[] args) { + Engine e = null; + + // load + try { + e = new Engine(); + SyncCallbacks callbacks = new SyncCallbacks(); + //e.setNotifyHandshakeCallback(callbacks); + e.setMessageToSendCallback(callbacks); + } + catch (pEpException ex) { + System.out.println("Cannot load"); + System.exit(-1); + } + System.out.println("Test loaded"); + + + e.startSync(); + + //It should crash here. + + try { + Thread.sleep(200); + } + catch (InterruptedException ex) { } + + System.exit(0); + } +} diff --git a/test/JNI_85/SyncCallbacks.java b/test/JNI_85/SyncCallbacks.java new file mode 100644 index 0000000..ee98582 --- /dev/null +++ b/test/JNI_85/SyncCallbacks.java @@ -0,0 +1,24 @@ +import foundation.pEp.jniadapter.*; + +public class SyncCallbacks implements Sync.MessageToSendCallback, Sync.NotifyHandshakeCallback { + public void messageToSend(Message message) + { + System.out.println("================================"); + System.out.println("Message to send called"); + System.out.println("From: " + message.getFrom()); + System.out.println("To: " + message.getTo()); + System.out.println("Subject: " + message.getShortmsg()); + System.out.println("================================"); + } + + public void notifyHandshake(Identity myself, Identity partner, SyncHandshakeSignal signal) + { + System.out.println("================================"); + System.out.println("Notify handshake called"); + System.out.println("Myself: " + myself); + System.out.println("Partner: " + partner); + System.out.println("Signal: " + signal); + System.out.println("================================"); + } +} + diff --git a/test/Makefile b/test/Makefile index 258fe3a..a75ffeb 100644 --- a/test/Makefile +++ b/test/Makefile @@ -23,12 +23,17 @@ VM=java -Xcheck:jni -Djava.library.path=../src test: Testing.class SyncCallbacks.class HOME=$(PWD) CLASSPATH=$(CLASSPATH) time $(VM) Testing +test-JNI-85: + $(MAKE) -C JNI_85 + %.class: %.java CLASSPATH=$(CLASSPATH) javac $< clean: + $(MAKE) -C JNI_85 clean rm -f *.class rm -f *.log rm -f .pEp_* + rm -Rf .pEp rm -Rf .gnupg rm -Rf .lldb