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 2 years ago
parent
commit
7621d7a306
26 changed files with 414 additions and 193 deletions
  1. +1
    -2
      .hgignore
  2. +2
    -2
      Makefile
  3. +0
    -27
      test/Basic/Makefile
  4. +0
    -32
      test/JNI-85/Makefile
  5. +0
    -26
      test/JNI-88/Makefile
  6. +0
    -26
      test/JNI-91/Makefile
  7. +0
    -18
      test/Makefile
  8. +0
    -18
      test/Makefile.conf
  9. +27
    -0
      test/java/foundation/pEp/jniadapter/test/Makefile
  10. +25
    -0
      test/java/foundation/pEp/jniadapter/test/Makefile.conf
  11. +33
    -0
      test/java/foundation/pEp/jniadapter/test/basic/Makefile
  12. +1
    -0
      test/java/foundation/pEp/jniadapter/test/basic/SyncCallbacks.java
  13. +30
    -26
      test/java/foundation/pEp/jniadapter/test/basic/TestMain.java
  14. +33
    -0
      test/java/foundation/pEp/jniadapter/test/jni85/Makefile
  15. +1
    -0
      test/java/foundation/pEp/jniadapter/test/jni85/Step1.java
  16. +1
    -8
      test/java/foundation/pEp/jniadapter/test/jni85/Step2.java
  17. +1
    -0
      test/java/foundation/pEp/jniadapter/test/jni85/SyncCallbacks.java
  18. +32
    -0
      test/java/foundation/pEp/jniadapter/test/jni88/Makefile
  19. +1
    -8
      test/java/foundation/pEp/jniadapter/test/jni88/TestMain.java
  20. +32
    -0
      test/java/foundation/pEp/jniadapter/test/jni91/Makefile
  21. +1
    -0
      test/java/foundation/pEp/jniadapter/test/jni91/TestMain.java
  22. +33
    -0
      test/java/foundation/pEp/jniadapter/test/jni92/Makefile
  23. +24
    -0
      test/java/foundation/pEp/jniadapter/test/jni92/SyncCallbacks.java
  24. +84
    -0
      test/java/foundation/pEp/jniadapter/test/jni92/TestMain.java
  25. +52
    -0
      test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java
  26. +0
    -0
      test/resources/test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc

+ 1
- 2
.hgignore View File

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

+ 2
- 2
Makefile View File

@ -24,14 +24,14 @@ endif
all: src
test: src
$(MAKE) -C test compile
$(MAKE) -C test/java/foundation/pEp/jniadapter/test/ compile
src:
$(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
doxy-all: doxy-cxx doxy-java


+ 0
- 27
test/Basic/Makefile View File

@ -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

+ 0
- 32
test/JNI-85/Makefile View File

@ -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

+ 0
- 26
test/JNI-88/Makefile View File

@ -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

+ 0
- 26
test/JNI-91/Makefile View File

@ -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

+ 0
- 18
test/Makefile View File

@ -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

+ 0
- 18
test/Makefile.conf View File

@ -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
- 0
test/java/foundation/pEp/jniadapter/test/Makefile View File

@ -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
- 0
test/java/foundation/pEp/jniadapter/test/Makefile.conf View File

@ -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
- 0
test/java/foundation/pEp/jniadapter/test/basic/Makefile View File

@ -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

test/Basic/SyncCallbacks.java → test/java/foundation/pEp/jniadapter/test/basic/SyncCallbacks.java View File


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


+ 33
- 0
test/java/foundation/pEp/jniadapter/test/jni85/Makefile View File

@ -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

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


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


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


+ 32
- 0
test/java/foundation/pEp/jniadapter/test/jni88/Makefile View File

@ -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

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


+ 32
- 0
test/java/foundation/pEp/jniadapter/test/jni91/Makefile View File

@ -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

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


+ 33
- 0
test/java/foundation/pEp/jniadapter/test/jni92/Makefile View File

@ -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
- 0
test/java/foundation/pEp/jniadapter/test/jni92/SyncCallbacks.java View File

@ -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
- 0
test/java/foundation/pEp/jniadapter/test/jni92/TestMain.java View File

@ -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
- 0
test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java View File

@ -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("");
}
}

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


Loading…
Cancel
Save