Browse Source

test/ dir complete restructuring into standard java project layout.

new package foundation.pEp.jniadapter.test
shared classes and resources now possible for tests.
Preparation for Test Framework and Code Coverage tool.
JNI-94
heck 5 years ago
parent
commit
7621d7a306
  1. 3
      .hgignore
  2. 4
      Makefile
  3. 27
      test/Basic/Makefile
  4. 32
      test/JNI-85/Makefile
  5. 26
      test/JNI-88/Makefile
  6. 26
      test/JNI-91/Makefile
  7. 18
      test/Makefile
  8. 18
      test/Makefile.conf
  9. 27
      test/java/foundation/pEp/jniadapter/test/Makefile
  10. 25
      test/java/foundation/pEp/jniadapter/test/Makefile.conf
  11. 33
      test/java/foundation/pEp/jniadapter/test/basic/Makefile
  12. 1
      test/java/foundation/pEp/jniadapter/test/basic/SyncCallbacks.java
  13. 56
      test/java/foundation/pEp/jniadapter/test/basic/TestMain.java
  14. 33
      test/java/foundation/pEp/jniadapter/test/jni85/Makefile
  15. 1
      test/java/foundation/pEp/jniadapter/test/jni85/Step1.java
  16. 9
      test/java/foundation/pEp/jniadapter/test/jni85/Step2.java
  17. 1
      test/java/foundation/pEp/jniadapter/test/jni85/SyncCallbacks.java
  18. 32
      test/java/foundation/pEp/jniadapter/test/jni88/Makefile
  19. 9
      test/java/foundation/pEp/jniadapter/test/jni88/TestMain.java
  20. 32
      test/java/foundation/pEp/jniadapter/test/jni91/Makefile
  21. 1
      test/java/foundation/pEp/jniadapter/test/jni91/TestMain.java
  22. 33
      test/java/foundation/pEp/jniadapter/test/jni92/Makefile
  23. 24
      test/java/foundation/pEp/jniadapter/test/jni92/SyncCallbacks.java
  24. 84
      test/java/foundation/pEp/jniadapter/test/jni92/TestMain.java
  25. 52
      test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java
  26. 0
      test/resources/test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc

3
.hgignore

@ -86,5 +86,4 @@ android/external/[^.]*
local.conf local.conf
src/local.conf src/local.conf
# Default ignored files # Default ignored files
.idea/workspace.xml .idea/
.idea/vcs.xml

4
Makefile

@ -24,14 +24,14 @@ endif
all: src all: src
test: src test: src
$(MAKE) -C test compile $(MAKE) -C test/java/foundation/pEp/jniadapter/test/ compile
src: src:
$(MAKE) -C src $(MAKE) -C src
clean: clean:
$(MAKE) -C src clean $(MAKE) -C src clean
$(MAKE) -C test clean $(MAKE) -C test/java/foundation/pEp/jniadapter/test/ clean clean-pep-home
# Generate API Documentation # Generate API Documentation
doxy-all: doxy-cxx doxy-java doxy-all: doxy-cxx doxy-java

27
test/Basic/Makefile

@ -1,27 +0,0 @@
include ../../Makefile.conf
include ../Makefile.conf
JAVA_CLASSES = \
Testing.class \
SyncCallbacks.class
.PHONY: compile run test clean
all: compile
$(MAKE) run
run: compile
HOME=$(PWD) CLASSPATH=$(CLASSPATH) time $(VM) Testing
compile: $(JAVA_CLASSES)
%.class: %.java
CLASSPATH=$(CLASSPATH) javac $<
clean:
rm -f *.class
rm -f *.log
rm -rf .pEp_*
rm -Rf .pEp
rm -Rf .gnupg
rm -Rf .lldb

32
test/JNI-85/Makefile

@ -1,32 +0,0 @@
include ../../Makefile.conf
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)
JAVA_CLASSES = \
SyncCallbacks.class \
Step1.class \
Step2.class
.PHONY: compile run test clean
all: compile
$(MAKE) run
run: compile
-HOME=$(PWD) CLASSPATH=$(CLASSPATH) time $(VM) Step1
HOME=$(PWD) CLASSPATH=$(CLASSPATH) time $(VM) Step2
compile: $(JAVA_CLASSES)
%.class: %.java
CLASSPATH=$(CLASSPATH) javac $<
clean:
rm -f *.class
rm -f *.log
rm -f .pEp_*
rm -Rf .pEp
rm -Rf .gnupg
rm -Rf .lldb

26
test/JNI-88/Makefile

@ -1,26 +0,0 @@
include ../../Makefile.conf
include ../Makefile.conf
JAVA_CLASSES = \
TestMain.class
.PHONY: compile run test clean
all: compile
$(MAKE) run
run: compile
HOME=$(PWD) CLASSPATH=$(CLASSPATH) time $(VM) TestMain
compile: $(JAVA_CLASSES)
%.class: %.java
CLASSPATH=$(CLASSPATH) javac $<
clean:
rm -f *.class
rm -f *.log
rm -rf .pEp_*
rm -Rf .pEp
rm -Rf .gnupg
rm -Rf .lldb

26
test/JNI-91/Makefile

@ -1,26 +0,0 @@
include ../../Makefile.conf
include ../Makefile.conf
JAVA_CLASSES = \
TestMain.class
.PHONY: compile run test clean
all: compile
$(MAKE) run
run: compile
HOME=$(PWD) CLASSPATH=$(CLASSPATH) time $(VM) TestMain
compile: $(JAVA_CLASSES)
%.class: %.java
CLASSPATH=$(CLASSPATH) javac $<
clean:
rm -f *.class
rm -f *.log
rm -rf .pEp_*
rm -Rf .pEp
rm -Rf .gnupg
rm -Rf .lldb

18
test/Makefile

@ -1,18 +0,0 @@
.PHONY: all compile run clean
all: compile
run: compile
$(MAKE) -C Basic run
$(MAKE) -C JNI-85 run
$(MAKE) -C JNI-88 run
compile:
$(MAKE) -C Basic compile
$(MAKE) -C JNI-85 compile
$(MAKE) -C JNI-88 compile
clean:
$(MAKE) -C Basic clean
$(MAKE) -C JNI-85 clean
$(MAKE) -C JNI-88 clean

18
test/Makefile.conf

@ -1,18 +0,0 @@
$(info If on Mac, make sure to disable SIP, or copy the libpEpEngine.dylib into here)
ifdef ENGINE_LIB_PATH
ifeq ($(BUILD_FOR),Linux)
ifndef LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$(ENGINE_LIB_PATH)
endif
else ifeq ($(BUILD_FOR),Darwin)
ifndef DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=$(ENGINE_LIB_PATH)
endif
endif
endif
CLASSPATH=.:../../src
VM=java -Xcheck:jni -Djava.library.path=../../src
#VM=lldb java -- -Xcheck:jni -Djava.library.path=../src

27
test/java/foundation/pEp/jniadapter/test/Makefile

@ -0,0 +1,27 @@
.PHONY: all compile run clean
all: compile
run: compile
$(MAKE) -C basic run
#BROKEN $(MAKE) -C jni85 run
$(MAKE) -C jni88 run
$(MAKE) -C jni91 run
$(MAKE) -C jni92 run
compile:
$(MAKE) -C basic compile
#BROKEN $(MAKE) -C jni85 compile
$(MAKE) -C jni88 compile
$(MAKE) -C jni91 compile
$(MAKE) -C jni92 compile
clean:
$(MAKE) -C basic clean
$(MAKE) -C jni85 clean
$(MAKE) -C jni88 clean
$(MAKE) -C jni91 clean
$(MAKE) -C jni92 clean
clean-pep-home:
$(MAKE) -C basic clean-pep-home

25
test/java/foundation/pEp/jniadapter/test/Makefile.conf

@ -0,0 +1,25 @@
JAVA_PKG_BASENAME=foundation.pEp.jniadapter.test
JAVA_PKG_BASEPATH=foundation/pEp/jniadapter/test
REPOROOT=../..
JAVA_CWD=../../../../../
JAVA_RESOURCES_DIR=../resources
JAVA_PEP_HOME_DIR=$(JAVA_RESOURCES_DIR)/pep-home
PEP_HOME_DIR=$(JAVA_CWD)$(JAVA_PEP_HOME_DIR)
CLASSPATH=.:$(REPOROOT)/src
JAVA=java -Xcheck:jni -cp $(CLASSPATH) -Djava.library.path=$(CLASSPATH)
$(info If on Mac, make sure to disable SIP, or copy the libpEpEngine.dylib into here)
ifdef ENGINE_LIB_PATH
ifeq ($(BUILD_FOR),Linux)
ifndef LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$(ENGINE_LIB_PATH)
endif
else ifeq ($(BUILD_FOR),Darwin)
ifndef DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=$(ENGINE_LIB_PATH)
endif
endif
endif

33
test/java/foundation/pEp/jniadapter/test/basic/Makefile

@ -0,0 +1,33 @@
include ../../../../../../../Makefile.conf
include ../Makefile.conf
TEST_UNIT_NAME=basic
JAVA_CLASSES = \
SyncCallbacks.class \
TestMain.class \
../utils/TestUtils.class
.PHONY: compile run test clean
all: compile
$(MAKE) run
run: compile
cd $(JAVA_CWD);HOME=$(JAVA_PEP_HOME_DIR) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestMain
compile: $(JAVA_CLASSES)
%.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:
rm -rf $(PEP_HOME_DIR)/*
rm -rf $(PEP_HOME_DIR)/.pEp

1
test/Basic/SyncCallbacks.java → test/java/foundation/pEp/jniadapter/test/basic/SyncCallbacks.java

@ -1,3 +1,4 @@
package foundation.pEp.jniadapter.test.basic;
import foundation.pEp.jniadapter.*; import foundation.pEp.jniadapter.*;
class SyncCallbacks implements Sync.MessageToSendCallback, Sync.NotifyHandshakeCallback { class SyncCallbacks implements Sync.MessageToSendCallback, Sync.NotifyHandshakeCallback {

56
test/Basic/Testing.java → test/java/foundation/pEp/jniadapter/test/basic/TestMain.java

@ -1,4 +1,6 @@
package foundation.pEp.jniadapter.test.basic;
import foundation.pEp.jniadapter.*; import foundation.pEp.jniadapter.*;
import foundation.pEp.jniadapter.test.utils.TestUtils;
import java.util.Vector; import java.util.Vector;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
@ -10,7 +12,7 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
class Testing { class TestMain {
public void printClassPath() { public void printClassPath() {
ClassLoader cl = ClassLoader.getSystemClassLoader(); ClassLoader cl = ClassLoader.getSystemClassLoader();
@ -22,14 +24,15 @@ class Testing {
} }
public static void main(String[] args) { public static void main(String[] args) {
Engine e; Engine engine;
TestUtils.log("fds");
// load // load
try { try {
e = new Engine(); engine = new Engine();
SyncCallbacks c = new SyncCallbacks();
SyncCallbacks callbacks = new SyncCallbacks(); SyncCallbacks callbacks = new SyncCallbacks();
//e.setNotifyHandshakeCallback(callbacks); // e.setNotifyHandshakeCallback(callbacks);
e.setMessageToSendCallback(callbacks); engine.setMessageToSendCallback(callbacks);
} }
catch (pEpException ex) { catch (pEpException ex) {
System.out.println("Cannot load"); System.out.println("Cannot load");
@ -44,15 +47,15 @@ class Testing {
user.me = true; user.me = true;
user.username = "Test User"; user.username = "Test User";
user.address = "jniTestUser@peptest.ch"; user.address = "jniTestUser@peptest.ch";
user = e.myself(user); user = engine.myself(user);
System.out.print("Keys generated: "); System.out.print("Keys generated: ");
System.out.println(user.fpr); System.out.println(user.fpr);
// Import key // Import key
try { try {
Path path = Paths.get("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc"); Path path = Paths.get("../resources/test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
byte[] key = Files.readAllBytes(path); byte[] key = Files.readAllBytes(path);
e.importKey(key); engine.importKey(key);
} catch (IOException exception) { } catch (IOException exception) {
System.out.println("Could not import key"); System.out.println("Could not import key");
exception.printStackTrace(); exception.printStackTrace();
@ -61,7 +64,7 @@ class Testing {
// trustwords // trustwords
Identity alice = new Identity(); Identity alice = new Identity();
alice.fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97"; alice.fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
String t = e.trustwords(alice); String t = engine.trustwords(alice);
System.out.print("Trustwords: "); System.out.print("Trustwords: ");
System.out.println(t); System.out.println(t);
@ -86,12 +89,12 @@ class Testing {
// Test setAttachements() with nrAttachemnts // Test setAttachements() with nrAttachemnts
int nrAttachemnts = 3; int nrAttachemnts = 3;
{ {
System.out.print("Adding " + String.valueOf(nrAttachemnts) + " attachements ["); System.out.print("Adding " + nrAttachemnts + " attachements [");
Vector<Blob> attachments = new Vector<>(); Vector<Blob> attachments = new Vector<>();
for (int i = 0; i < nrAttachemnts; i++) { for (int i = 0; i < nrAttachemnts; i++) {
Blob blb = new Blob(); Blob blb = new Blob();
String dataString = "Attachement nr: " + String.valueOf(i) + " [TEST DATA]"; String dataString = "Attachement nr: " + i + " [TEST DATA]";
blb.data = dataString.getBytes(); blb.data = dataString.getBytes();
blb.filename = "testfilename.txt"; blb.filename = "testfilename.txt";
attachments.add(blb); attachments.add(blb);
@ -103,7 +106,7 @@ class Testing {
Message enc = null; Message enc = null;
try { try {
enc = e.encrypt_message(msg, null, Message.EncFormat.PEP); enc = engine.encrypt_message(msg, null, Message.EncFormat.PEP);
System.out.println("encrypted"); System.out.println("encrypted");
} }
catch (pEpException ex) { catch (pEpException ex) {
@ -114,8 +117,8 @@ class Testing {
System.out.println(enc.getLongmsg()); System.out.println(enc.getLongmsg());
try { try {
System.out.println("Rating preview: " + e.outgoing_message_rating_preview(msg)); System.out.println("Rating preview: " + engine.outgoing_message_rating_preview(msg));
System.out.println("Rating" + e.outgoing_message_rating(msg)); System.out.println("Rating" + engine.outgoing_message_rating(msg));
} }
catch (pEpException ex) { catch (pEpException ex) {
System.out.println("cannot measure outgoing message rating"); System.out.println("cannot measure outgoing message rating");
@ -123,7 +126,7 @@ class Testing {
Engine.decrypt_message_Return result = null; Engine.decrypt_message_Return result = null;
try { try {
result = e.decrypt_message(enc, new Vector<>(), 0); result = engine.decrypt_message(enc, new Vector<>(), 0);
System.out.println("decrypted"); System.out.println("decrypted");
} }
catch (pEpException ex) { catch (pEpException ex) {
@ -140,9 +143,9 @@ class Testing {
Vector<Blob> attachments = result.dst.getAttachments(); Vector<Blob> attachments = result.dst.getAttachments();
System.out.println("get attachement data"); System.out.println("get attachement data");
System.out.println("Attachement count: " + String.valueOf(attachments.size())); System.out.println("Attachement count: " + attachments.size());
for( Blob a: attachments) { for( Blob a: attachments) {
System.out.println("Attachement nr: " + String.valueOf(attachments.indexOf(a))); System.out.println("Attachement nr: " + attachments.indexOf(a));
System.out.println("["); System.out.println("[");
System.out.println(a.toString()); System.out.println(a.toString());
System.out.println("]"); System.out.println("]");
@ -152,15 +155,15 @@ class Testing {
System.out.println("TEST DONE - FINISHED"); System.out.println("TEST DONE - FINISHED");
try { try {
e.key_reset_all_own_keys(); engine.key_reset_all_own_keys();
} }
catch (pEpException ex) { catch (pEpException ex) {
System.out.println("cannot reset all own keys"); System.out.println("cannot reset all own keys");
ex.printStackTrace(); ex.printStackTrace();
} }
System.out.println("Testing.java: e.StartSync()");
e.startSync(); System.out.println("Testing.java: e.StartSync()");
engine.startSync();
// Keygen // Keygen
System.out.println("Generating keys: "); System.out.println("Generating keys: ");
@ -175,14 +178,15 @@ class Testing {
// it's not necessary - you can just shutdown Sync and that's it // 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 // but for this test give sync a chance to process all messages
// try { try {
// Thread.sleep(200); Thread.sleep(2000);
// } }
// catch (InterruptedException ex) { } catch (InterruptedException ex) { }
System.out.println("STOP SYNC"); System.out.println("STOP SYNC");
e.stopSync(); engine.stopSync();
System.exit(0); System.exit(0);
} }
} }

33
test/java/foundation/pEp/jniadapter/test/jni85/Makefile

@ -0,0 +1,33 @@
include ../../../../../../../Makefile.conf
include ../Makefile.conf
TEST_UNIT_NAME=jni85
JAVA_CLASSES = \
Step1.class \
Step2.class \
../utils/TestUtils.class
.PHONY: compile run test clean
all: compile
$(MAKE) run
run: compile
cd $(JAVA_CWD);HOME=$(JAVA_PEP_HOME_DIR) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestMain
compile: $(JAVA_CLASSES)
%.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:
rm -rf $(PEP_HOME_DIR)/*
rm -rf $(PEP_HOME_DIR)/.pEp

1
test/JNI-85/Step1.java → test/java/foundation/pEp/jniadapter/test/jni85/Step1.java

@ -1,3 +1,4 @@
package foundation.pEp.jniadapter.test.jni85;
import foundation.pEp.jniadapter.*; import foundation.pEp.jniadapter.*;
import java.util.Vector; import java.util.Vector;
import java.net.URL; import java.net.URL;

9
test/JNI-85/Step2.java → test/java/foundation/pEp/jniadapter/test/jni85/Step2.java

@ -1,15 +1,8 @@
package foundation.pEp.jniadapter.test.jni85;
import foundation.pEp.jniadapter.*; import foundation.pEp.jniadapter.*;
import java.util.Vector;
import java.net.URL;
import java.net.URLClassLoader;
import java.lang.Thread; import java.lang.Thread;
import java.lang.InterruptedException; 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 { class Step2 {
public static void main(String[] args) { public static void main(String[] args) {

1
test/JNI-85/SyncCallbacks.java → test/java/foundation/pEp/jniadapter/test/jni85/SyncCallbacks.java

@ -1,3 +1,4 @@
package foundation.pEp.jniadapter.test.jni85;
import foundation.pEp.jniadapter.*; import foundation.pEp.jniadapter.*;
public class SyncCallbacks implements Sync.MessageToSendCallback, Sync.NotifyHandshakeCallback { public class SyncCallbacks implements Sync.MessageToSendCallback, Sync.NotifyHandshakeCallback {

32
test/java/foundation/pEp/jniadapter/test/jni88/Makefile

@ -0,0 +1,32 @@
include ../../../../../../../Makefile.conf
include ../Makefile.conf
TEST_UNIT_NAME=jni88
JAVA_CLASSES = \
TestMain.class \
../utils/TestUtils.class
.PHONY: compile run test clean
all: compile
$(MAKE) run
run: compile
cd $(JAVA_CWD);HOME=$(JAVA_PEP_HOME_DIR) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestMain
compile: $(JAVA_CLASSES)
%.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:
rm -rf $(PEP_HOME_DIR)/*
rm -rf $(PEP_HOME_DIR)/.pEp

9
test/JNI-88/TestMain.java → test/java/foundation/pEp/jniadapter/test/jni88/TestMain.java

@ -1,14 +1,7 @@
package foundation.pEp.jniadapter.test.jni88;
import foundation.pEp.jniadapter.*; import foundation.pEp.jniadapter.*;
import java.util.Vector; import java.util.Vector;
import java.net.URL;
import java.net.URLClassLoader;
import java.lang.Thread; 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;
/* /*

32
test/java/foundation/pEp/jniadapter/test/jni91/Makefile

@ -0,0 +1,32 @@
include ../../../../../../../Makefile.conf
include ../Makefile.conf
TEST_UNIT_NAME=jni91
JAVA_CLASSES = \
TestMain.class \
../utils/TestUtils.class
.PHONY: compile run test clean
all: compile
$(MAKE) run
run: compile
cd $(JAVA_CWD);HOME=$(JAVA_PEP_HOME_DIR) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestMain
compile: $(JAVA_CLASSES)
%.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:
rm -rf $(PEP_HOME_DIR)/*
rm -rf $(PEP_HOME_DIR)/.pEp

1
test/JNI-91/TestMain.java → test/java/foundation/pEp/jniadapter/test/jni91/TestMain.java

@ -1,3 +1,4 @@
package foundation.pEp.jniadapter.test.jni91;
import foundation.pEp.jniadapter.*; import foundation.pEp.jniadapter.*;
import java.lang.Thread; import java.lang.Thread;

33
test/java/foundation/pEp/jniadapter/test/jni92/Makefile

@ -0,0 +1,33 @@
include ../../../../../../../Makefile.conf
include ../Makefile.conf
TEST_UNIT_NAME=jni92
JAVA_CLASSES = \
SyncCallbacks.class \
TestMain.class \
../utils/TestUtils.class
.PHONY: compile run test clean
all: compile
$(MAKE) run
run: compile
cd $(JAVA_CWD);HOME=$(JAVA_PEP_HOME_DIR) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestMain
compile: $(JAVA_CLASSES)
%.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:
rm -rf $(PEP_HOME_DIR)/*
rm -rf $(PEP_HOME_DIR)/.pEp

24
test/java/foundation/pEp/jniadapter/test/jni92/SyncCallbacks.java

@ -0,0 +1,24 @@
package foundation.pEp.jniadapter.test.jni92;
import foundation.pEp.jniadapter.test.utils.TestUtils;
import foundation.pEp.jniadapter.*;
class SyncCallbacks implements Sync.MessageToSendCallback, Sync.NotifyHandshakeCallback {
public void messageToSend(Message message)
{
TestUtils.logH2("Message to send called");
TestUtils.log("From: " + message.getFrom());
TestUtils.log("To: " + message.getTo());
TestUtils.log("Subject: " + message.getShortmsg());
TestUtils.log("Attachement[0]: " + message.getAttachments().get(0).toString());
TestUtils.logSectEnd();
}
public void notifyHandshake(Identity myself, Identity partner, SyncHandshakeSignal signal)
{
TestUtils.logH2("Notify handshake called");
TestUtils.log("Myself: " + myself);
TestUtils.log("Partner: " + partner);
TestUtils.log("Signal: " + signal);
TestUtils.logSectEnd();
}
}

84
test/java/foundation/pEp/jniadapter/test/jni92/TestMain.java

@ -0,0 +1,84 @@
package foundation.pEp.jniadapter.test.jni92;
import foundation.pEp.jniadapter.test.utils.TestUtils;
import foundation.pEp.jniadapter.*;
import java.lang.Thread;
import java.util.Vector;
/*
This test is trying to reproduce the problem described in JNI-91
https://pep.foundation/jira/browse/JNI-81
`engine.key_reset_identity` and `engine.setMessageToSendCallback`
*/
class TestThread extends Thread {
private String threadName = "TestThread-1";
private Engine engine = null;
TestThread(String threadName) {
this.threadName = threadName;
}
public void run() {
TestUtils.logH1(threadName + ": Starting thread");
try {
// load engine
try {
engine = new Engine();
SyncCallbacks callbacks = new SyncCallbacks();
engine.setMessageToSendCallback(callbacks);
engine.setNotifyHandshakeCallback(callbacks);
} catch (pEpException ex) {
TestUtils.log(threadName + ": cannot load");
return;
}
TestUtils.log(threadName + ": Engine loaded");
if(!engine.isSyncRunning()) {
engine.startSync();
}
} catch (Exception e) {
TestUtils.log("Exception in Thread " + threadName);
TestUtils.log(e.toString());
}
TestUtils.sleep(20000);
if(engine.isSyncRunning()) {
engine.stopSync();
}
TestUtils.log(threadName + ": DONE");
}
}
class TestMain {
public static void main(String[] args) throws Exception {
TestUtils.logH1("JNI-92 Starting");
Vector<TestThread> tts = new Vector<TestThread>();
int nrThreads = 3;
for(int i = 0; i < nrThreads; i++){
tts.add(new TestThread("TestThread-" + i));
}
tts.forEach( t -> {
t.start();
TestUtils.sleep(2000);
});
tts.forEach( t -> {
try {
t.join();
} catch(Exception e ){
TestUtils.log("Exception joining thread" + e.toString());
}
});
}
}

52
test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java

@ -0,0 +1,52 @@
package foundation.pEp.jniadapter.test.utils;
import foundation.pEp.jniadapter.*;
public class TestUtils {
public static void sleep(int mSec) {
try {
Thread.sleep(mSec);
} catch (InterruptedException ex) {
System.out.println("sleep got interrupted");
}
}
public static String identityToString(Identity i) {
String ret = "address: " + i.address + "\n";
ret += "fpr: " + i.fpr + "\n";
ret += "username: " + i.username + "\n";
ret += "user_id: " + i.user_id + "\n";
ret += "flags: " + i.flags + "\n";
ret += "lang: " + i.lang + "\n";
ret += "me: " + i.me + "\n";
ret += "comm_type: " + i.comm_type;
return ret;
}
public static void log(String msg) {
System.out.println(msg);
}
public static void logH1(String msg) {
String decorationStr = getDecoratorString(msg, "=");
System.out.println(decorationStr + " " + msg.toUpperCase() + " " + decorationStr);
}
public static void logH2(String msg) {
String decorationStr = getDecoratorString(msg, "-");
System.out.println(decorationStr + " " + msg + " " + decorationStr);
}
private static String getDecoratorString(String msg, String s) {
int lineWidth = 80;
String decorationChar = s;
String decorationStr = "";
for (int i = 0; i < Math.ceil((lineWidth - msg.length() + 2) / 2); i++) {
decorationStr += decorationChar;
}
return decorationStr;
}
public static void logSectEnd() {
System.out.println("");
}
}

0
test/Basic/test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc → test/resources/test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc

Loading…
Cancel
Save