diff --git a/.hgignore b/.hgignore index 1eedcac..d83d981 100644 --- a/.hgignore +++ b/.hgignore @@ -12,6 +12,8 @@ syntax: glob *.orig *~ .DS_Store +*.db +*.log # ignore generated files diff --git a/Makefile b/Makefile index 917566f..45acece 100644 --- a/Makefile +++ b/Makefile @@ -3,32 +3,16 @@ # This file may be used under the terms of the GNU General Public License version 3 # see LICENSE.txt -HERE_REL := $(notdir $(CURDIR)) - -include Makefile.conf - -ifneq ($(wildcard local.conf),) - $(info ================================================) - $(info Overrides in `local.conf` are used.) - $(info ================================================) -endif - -ifdef BUILD_CONFIG - $(info ================================================) - $(info Overrides in `$(BUILD_CONFIG)` are used.) - $(info ================================================) -endif - -.PHONY: all src test clean +.PHONY: all src test clean doxy-all doxy-cxx doxy-java doxy-clean all: src -test: src - $(MAKE) -C test/java/foundation/pEp/jniadapter/test/ compile - src: $(MAKE) -C src +test: src + $(MAKE) -C test/java/foundation/pEp/jniadapter/test/ compile + clean: $(MAKE) -C src clean $(MAKE) -C test/java/foundation/pEp/jniadapter/test/ clean clean-pep-home diff --git a/Makefile.conf b/Makefile.conf index 36bd911..15c9dde 100644 --- a/Makefile.conf +++ b/Makefile.conf @@ -6,28 +6,10 @@ HERE:=$(dir $(lastword $(MAKEFILE_LIST))) PLATFORM:=$(shell uname | tr A-Z a-z) -# Guessing JAVA_HOME -ifeq ($(PLATFORM),linux) - JAVA_HOME=$(subst /bin,,$(dir $(realpath /usr/bin/javac))) -endif - -######### C and C++ ######### -CXXFLAGS+=-O0 -std=c++11 -LDFLAGS+=-shared $(ENGINE_LIB) $(AD_LIB) - -LDLIBS=-lstdc++ -lpEpEngine -lpEpAdapter - -CXXFLAGS+=-fpermissive -fPIC -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/$(PLATFORM) $(AD_INC) $(ENGINE_INC) -ifneq (,$(findstring g++,$(CXX))) - CXXFLAGS+=-fdiagnostics-color=always -else ifneq (,$(findstring clang,$(CXX))) - CXXFLAGS+=-fcolor-diagnostics -endif - - # DEV ENV PATHS & CFG # The dev environment paths and configs are set to a default value which can be overridden by ./local.conf and overridden again by /local.conf -######### Default paths for dependencies ######### +######### Build Config Defaults ######### +DEBUG=1 YML2_PATH=$(HOME)/yml2 YML2_PROC=$(YML2_PATH)/yml2proc $(YML2_OPTS) YML2_OPTS=--encoding=utf8 @@ -35,22 +17,46 @@ ENGINE_LIB_PATH=$(HOME)/lib ENGINE_INC_PATH=$(HOME)/include AD_LIB_PATH=$(HOME)/lib AD_INC_PATH=$(HOME)/include -DEBUG=1 + +### Guessing JAVA_HOME +ifeq ($(PLATFORM),linux) + JAVA_HOME=$(subst /bin,,$(dir $(realpath /usr/bin/javac))) +endif + ######### Overrides from the config file(s) ######### --include $(HERE)/local.conf --include $(HERE)/src/local.conf +ifneq ("$(wildcard $(HERE)local.conf)","") + $(info including: $(HERE)local.conf) + -include $(HERE)local.conf +else + $(info Optional build config not found: $(HERE)local.conf) +endif + +ifneq ("$(wildcard $(HERE)src/local.conf)","") + $(info including: $(HERE)src/local.conf) + -include $(HERE)src/local.conf +else + $(info Optional build config not found: $(HERE)src/local.conf) +endif +### Apply config ENGINE_LIB=-L$(ENGINE_LIB_PATH) ENGINE_INC=-I$(ENGINE_INC_PATH) AD_LIB=-L$(AD_LIB_PATH) AD_INC=-I$(AD_INC_PATH) -ifdef BUILD_CONFIG - include $(BUILD_CONFIG) + +######### C and C++ ######### +CXXFLAGS+=-O0 -std=c++11 -fpermissive -fPIC -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/$(PLATFORM) $(AD_INC) $(ENGINE_INC) +LDFLAGS+=-shared $(ENGINE_LIB) $(AD_LIB) +LDLIBS=-lstdc++ -lpEpEngine -lpEpAdapter +ifneq (,$(findstring g++,$(CXX))) + CXXFLAGS+=-fdiagnostics-color=always +else ifneq (,$(findstring clang,$(CXX))) + CXXFLAGS+=-fcolor-diagnostics endif -# Debug or Release build +### Debug or Release build ifeq ($(DEBUG),1) $(info Debug build (set DEBUG=0 for release build)) CXXFLAGS+=-g @@ -59,5 +65,6 @@ else CXXFLAGS+=-DNDEBUG=1 endif -# YML_PATH is needed in the environment of every call to a program of the YML2 distribution +### YML_PATH is needed in the environment of every call to a program of the YML2 distribution export YML_PATH=$(YML2_PATH) + diff --git a/src/Makefile b/src/Makefile index e4ba5f5..29ba667 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,6 +5,19 @@ include ../Makefile.conf +$(info PLATFORM: $(PLATFORM)) +$(info DEBUG: $(DEBUG)) +$(info CXX: $(CXX)) +$(info JAVA_HOME: $(JAVA_HOME)) +$(info ENGINE_LIB_PATH: $(ENGINE_LIB_PATH)) +$(info ENGINE_INC_PATH: $(ENGINE_INC_PATH)) +$(info AD_LIB_PATH: $(AD_LIB_PATH)) +$(info AD_INC_PATH: $(AD_INC_PATH)) +$(info YML2_PATH: $(YML2_PATH)) +$(info CXXFLAGS: $(CXXFLAGS)) +$(info LDFLAGS: $(LDFLAGS)) +$(info LDLIBS: $(LDLIBS)) + ifndef JAVA_HOME $(error JAVA_HOME is not set!) endif diff --git a/test/java/foundation/pEp/jniadapter/test/Makefile b/test/java/foundation/pEp/jniadapter/test/Makefile index d154fbf..8fad575 100644 --- a/test/java/foundation/pEp/jniadapter/test/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/Makefile @@ -3,9 +3,9 @@ all: compile run: compile + $(MAKE) -C template run $(MAKE) -C basic run $(MAKE) -C regression run -#BROKEN $(MAKE) -C jni85 run $(MAKE) -C jni88 run $(MAKE) -C jni91 run $(MAKE) -C jni92 run @@ -13,9 +13,9 @@ run: compile $(MAKE) -C jni98 run compile: + $(MAKE) -C template compile $(MAKE) -C basic compile $(MAKE) -C regression compile -#BROKEN $(MAKE) -C jni85 compile $(MAKE) -C jni88 compile $(MAKE) -C jni91 compile $(MAKE) -C jni92 compile @@ -23,9 +23,9 @@ compile: $(MAKE) -C jni98 compile clean: + $(MAKE) -C template clean $(MAKE) -C basic clean $(MAKE) -C regression clean - $(MAKE) -C jni85 clean $(MAKE) -C jni88 clean $(MAKE) -C jni91 clean $(MAKE) -C jni92 clean diff --git a/test/java/foundation/pEp/jniadapter/test/Makefile.conf b/test/java/foundation/pEp/jniadapter/test/Makefile.conf index 0504c6a..bddc9d6 100644 --- a/test/java/foundation/pEp/jniadapter/test/Makefile.conf +++ b/test/java/foundation/pEp/jniadapter/test/Makefile.conf @@ -3,12 +3,18 @@ JAVA_PKG_BASEPATH=foundation/pEp/jniadapter/test REPOROOT=../.. JAVA_CWD=../../../../../ JAVA_RESOURCES_DIR=../resources -JAVA_PEP_HOME_DIR=$(JAVA_RESOURCES_DIR)/pep-home +JAVA_PEP_HOME_DIR=$(JAVA_RESOURCES_DIR)/per-user-dirs PEP_HOME_DIR=$(JAVA_CWD)$(JAVA_PEP_HOME_DIR) CLASSPATH=.:$(REPOROOT)/src JAVA=java -Xcheck:jni -cp $(CLASSPATH) -Djava.library.path=$(CLASSPATH) +JAVA_CLASSES_FRAMEWORK= \ + ../framework/TestUnit.class \ + ../framework/AbstractTestContext.class \ + ../framework/TestLogger.class \ + ../framework/TestUtils.class + ifdef ENGINE_LIB_PATH ifeq ($(PLATFORM),linux) diff --git a/test/java/foundation/pEp/jniadapter/test/basic/Makefile b/test/java/foundation/pEp/jniadapter/test/basic/Makefile index 440b729..1383458 100644 --- a/test/java/foundation/pEp/jniadapter/test/basic/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/basic/Makefile @@ -5,15 +5,15 @@ TEST_UNIT_NAME=basic JAVA_CLASSES = \ SyncCallbacks.class \ - TestMain.class \ - ../utils/TestUtils.class + TestMain.class + .PHONY: compile run test clean all: compile $(MAKE) run -run: compile +run: compile clean-pep-home cd $(JAVA_CWD);HOME=$(JAVA_PEP_HOME_DIR) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestMain compile: $(JAVA_CLASSES) diff --git a/test/java/foundation/pEp/jniadapter/test/basic/TestMain.java b/test/java/foundation/pEp/jniadapter/test/basic/TestMain.java index df44d03..d326246 100644 --- a/test/java/foundation/pEp/jniadapter/test/basic/TestMain.java +++ b/test/java/foundation/pEp/jniadapter/test/basic/TestMain.java @@ -1,6 +1,6 @@ package foundation.pEp.jniadapter.test.basic; import foundation.pEp.jniadapter.*; -import foundation.pEp.jniadapter.test.utils.TestUtils; + import java.util.Vector; import java.net.URL; import java.net.URLClassLoader; @@ -28,7 +28,6 @@ class TestMain { // load try { engine = new Engine(); - SyncCallbacks c = new SyncCallbacks(); SyncCallbacks callbacks = new SyncCallbacks(); // e.setNotifyHandshakeCallback(callbacks); engine.setMessageToSendCallback(callbacks); @@ -171,7 +170,7 @@ class TestMain { user2.me = true; user2.username = "Test User 2"; user2.address = "jniTestUser2@peptest.ch"; -// user2 = e.myself(user2); + user2 = engine.myself(user2); System.out.print("Keys generated: "); System.out.println(user2.fpr); diff --git a/test/java/foundation/pEp/jniadapter/test/framework/AbstractTestContext.java b/test/java/foundation/pEp/jniadapter/test/framework/AbstractTestContext.java new file mode 100644 index 0000000..92cb36d --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/framework/AbstractTestContext.java @@ -0,0 +1,5 @@ +package foundation.pEp.jniadapter.test.framework; + +public interface AbstractTestContext { + void init() throws Throwable; +} \ No newline at end of file diff --git a/test/java/foundation/pEp/jniadapter/test/framework/TestLogger.java b/test/java/foundation/pEp/jniadapter/test/framework/TestLogger.java new file mode 100644 index 0000000..d3c594f --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/framework/TestLogger.java @@ -0,0 +1,53 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package foundation.pEp.jniadapter.test.framework; + +public class TestLogger { + private static boolean logEnabled = true; + + public TestLogger() { + } + + public static void setLoggingEnabled(boolean enabled) { + logEnabled = enabled; + } + + public static boolean isLoggingEnabled() { + return logEnabled; + } + + public static void log(String msg) { + if (logEnabled) { + String threadStr = String.format("%-10s", Thread.currentThread().getName()); + String logStr = threadStr + ": " + msg; + System.out.println(logStr); + } + + } + + public static void logH1(String msg) { + log(getDecoratedString(msg, "=")); + } + + public static void logH2(String msg) { + log(getDecoratedString(msg, "-")); + } + + private static String getDecoratedString(String msg, String decoration) { + byte var2 = 80; + String ret = ""; + + for(int i = 0; (double)i < Math.ceil((double)((var2 - msg.length() + 2) / 2)); ++i) { + ret = ret + decoration; + } + + return ret + " " + msg + " " + ret; + } + + public static void logSectEnd(String msg) { + log(msg + "\n"); + } +} diff --git a/test/java/foundation/pEp/jniadapter/test/framework/TestUnit.java b/test/java/foundation/pEp/jniadapter/test/framework/TestUnit.java new file mode 100644 index 0000000..4df9ba2 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/framework/TestUnit.java @@ -0,0 +1,32 @@ +package foundation.pEp.jniadapter.test.framework; + +import java.util.function.Consumer; + +public class TestUnit implements Runnable { + String testUnitName = "default test unit"; + T ctx; + Consumer lambda; + + public TestUnit(String name, T context, Consumer lambda) { + this.testUnitName = name; + this.lambda = lambda; + this.ctx = context; + } + + public void run() { + TestLogger.logH1(testUnitName); + + try { + //Init the Context + ctx.init(); + //Run the test against the context + lambda.accept(ctx); + } catch (Throwable t) { + //Test fails, upon cought exception, otherwise succeeds + TestLogger.logH1("TestUnit FAILED: " + t.toString()); + return; + } + + TestLogger.logH2("SUCCESS!"); + } +} diff --git a/test/java/foundation/pEp/jniadapter/test/framework/TestUtils.java b/test/java/foundation/pEp/jniadapter/test/framework/TestUtils.java new file mode 100644 index 0000000..2748782 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/framework/TestUtils.java @@ -0,0 +1,12 @@ +package foundation.pEp.jniadapter.test.framework; + +public class TestUtils { + + public static void sleep(int mSec) { + try { + Thread.sleep(mSec); + } catch (InterruptedException ex) { + System.out.println("sleep got interrupted"); + } + } +} \ No newline at end of file diff --git a/test/java/foundation/pEp/jniadapter/test/framework/examples/Makefile.conf b/test/java/foundation/pEp/jniadapter/test/framework/examples/Makefile.conf new file mode 100644 index 0000000..8c12ccd --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/framework/examples/Makefile.conf @@ -0,0 +1,10 @@ +JAVA_PKG_BASENAME=foundation.pEp.jniadapter.test.framework.examples +JAVA_PKG_BASEPATH=foundation/pEp/jniadapter/test/framework/examples +JAVA_CWD=../../../../../../../ +JAVA=java + +JAVA_CLASSES_FRAMEWORK= \ + ../../TestUnit.class \ + ../../AbstractTestContext.class \ + ../../TestLogger.class \ + ../../TestUtils.class diff --git a/test/java/foundation/pEp/jniadapter/test/framework/examples/helloworld/Makefile b/test/java/foundation/pEp/jniadapter/test/framework/examples/helloworld/Makefile new file mode 100644 index 0000000..de97c29 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/framework/examples/helloworld/Makefile @@ -0,0 +1,25 @@ +include ../Makefile.conf + +TEST_UNIT_NAME=helloworld + +JAVA_CLASSES = \ + TestMain.class \ + +# Use the test framework +JAVA_CLASSES += $(JAVA_CLASSES_FRAMEWORK) + +.PHONY: compile run test clean + +all: compile + $(MAKE) run + +run: compile + cd $(JAVA_CWD);$(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestMain + +compile: $(JAVA_CLASSES) + +%.class: %.java + cd $(JAVA_CWD);pwd;javac $(JAVA_PKG_BASEPATH)/$(TEST_UNIT_NAME)/$< + +clean: + rm -f $(JAVA_CLASSES) diff --git a/test/java/foundation/pEp/jniadapter/test/framework/examples/helloworld/TestMain.java b/test/java/foundation/pEp/jniadapter/test/framework/examples/helloworld/TestMain.java new file mode 100644 index 0000000..60f96b4 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/framework/examples/helloworld/TestMain.java @@ -0,0 +1,23 @@ +package foundation.pEp.jniadapter.test.framework.examples.helloworld; +import foundation.pEp.jniadapter.test.framework.*; + +class HelloWorldTestContext implements AbstractTestContext { + String name; + + @Override + public void init() throws Throwable { + name = "UnitTestFrameWorkWithoutAName"; + } +} + +class TestMain { + public static void main(String[] args) throws Exception { + new TestUnit("Hello World",new HelloWorldTestContext() , ctx -> { + // do stuff using the context + // Test FAILS on unhandled exception, otherwise SUCCESS + TestLogger.log("Hello World from: " + ctx.name); + }).run(); + } +} + + diff --git a/test/java/foundation/pEp/jniadapter/test/jni100/Makefile b/test/java/foundation/pEp/jniadapter/test/jni100/Makefile new file mode 100644 index 0000000..1b41e07 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/jni100/Makefile @@ -0,0 +1,35 @@ +include ../../../../../../../Makefile.conf +include ../Makefile.conf + +TEST_UNIT_NAME=jni100 + +JAVA_CLASSES = \ + TestMain.class \ + ../utils/AdapterTestUtils.class \ + ../utils/TestCallbacks.class + +JAVA_CLASSES += $(JAVA_CLASSES_FRAMEWORK) + +.PHONY: compile run test clean + +all: compile + $(MAKE) run + +run: compile clean-pep-home + cd $(JAVA_CWD);pwd;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 \ No newline at end of file diff --git a/test/java/foundation/pEp/jniadapter/test/jni100/TestMain.java b/test/java/foundation/pEp/jniadapter/test/jni100/TestMain.java new file mode 100644 index 0000000..347f18b --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/jni100/TestMain.java @@ -0,0 +1,27 @@ +package foundation.pEp.jniadapter.test.jni100; +import foundation.pEp.jniadapter.test.framework.*; +import foundation.pEp.jniadapter.*; +import foundation.pEp.jniadapter.test.utils.*; + + +class TestMain { + public static void main(String[] args) throws Exception { + new TestUnit("JNI-100",new AdapterBaseTestContext() , ctx -> { + TestCallbacks cb = new TestCallbacks(); + + ctx.engine.setMessageToSendCallback(cb); + ctx.engine.setNotifyHandshakeCallback(cb); + + ctx.alice = ctx.engine.myself(ctx.alice); + TestLogger.log(AdapterTestUtils.identityToString(ctx.alice, true)); + + Message msg1 = ctx.engine.encrypt_message(ctx.msgToBob, ctx.vStr, Message.EncFormat.PEP); + + ctx.engine.key_reset_all_own_keys(); + + TestLogger.log(AdapterTestUtils.identityToString(ctx.alice, true)); + }).run(); + } +} + + diff --git a/test/java/foundation/pEp/jniadapter/test/jni85/Step1.java b/test/java/foundation/pEp/jniadapter/test/jni85/Step1.java deleted file mode 100644 index e5e8ad5..0000000 --- a/test/java/foundation/pEp/jniadapter/test/jni85/Step1.java +++ /dev/null @@ -1,58 +0,0 @@ -package foundation.pEp.jniadapter.test.jni85; -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/java/foundation/pEp/jniadapter/test/jni85/Step2.java b/test/java/foundation/pEp/jniadapter/test/jni85/Step2.java deleted file mode 100644 index 578541f..0000000 --- a/test/java/foundation/pEp/jniadapter/test/jni85/Step2.java +++ /dev/null @@ -1,36 +0,0 @@ -package foundation.pEp.jniadapter.test.jni85; -import foundation.pEp.jniadapter.*; -import java.lang.Thread; -import java.lang.InterruptedException; - -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/java/foundation/pEp/jniadapter/test/jni85/SyncCallbacks.java b/test/java/foundation/pEp/jniadapter/test/jni85/SyncCallbacks.java deleted file mode 100644 index 37ec4d0..0000000 --- a/test/java/foundation/pEp/jniadapter/test/jni85/SyncCallbacks.java +++ /dev/null @@ -1,25 +0,0 @@ -package foundation.pEp.jniadapter.test.jni85; -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/java/foundation/pEp/jniadapter/test/jni88/Makefile b/test/java/foundation/pEp/jniadapter/test/jni88/Makefile index 1bd434a..e8aa7aa 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni88/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/jni88/Makefile @@ -4,15 +4,14 @@ include ../Makefile.conf TEST_UNIT_NAME=jni88 JAVA_CLASSES = \ - TestMain.class \ - ../utils/TestUtils.class + TestMain.class .PHONY: compile run test clean all: compile $(MAKE) run -run: compile +run: compile clean-pep-home cd $(JAVA_CWD);HOME=$(JAVA_PEP_HOME_DIR) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestMain compile: $(JAVA_CLASSES) diff --git a/test/java/foundation/pEp/jniadapter/test/jni91/Makefile b/test/java/foundation/pEp/jniadapter/test/jni91/Makefile index 78ee0da..71fb5b6 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni91/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/jni91/Makefile @@ -4,15 +4,14 @@ include ../Makefile.conf TEST_UNIT_NAME=jni91 JAVA_CLASSES = \ - TestMain.class \ - ../utils/TestUtils.class + TestMain.class .PHONY: compile run test clean all: compile $(MAKE) run -run: compile +run: compile clean-pep-home cd $(JAVA_CWD);HOME=$(JAVA_PEP_HOME_DIR) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestMain compile: $(JAVA_CLASSES) diff --git a/test/java/foundation/pEp/jniadapter/test/jni92/Makefile b/test/java/foundation/pEp/jniadapter/test/jni92/Makefile index 452e73e..b1a5f4a 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni92/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/jni92/Makefile @@ -4,16 +4,17 @@ include ../Makefile.conf TEST_UNIT_NAME=jni92 JAVA_CLASSES = \ - SyncCallbacks.class \ TestMain.class \ - ../utils/TestUtils.class + ../utils/AdapterTestUtils.class + +JAVA_CLASSES += $(JAVA_CLASSES_FRAMEWORK) .PHONY: compile run test clean all: compile $(MAKE) run -run: compile +run: compile clean-pep-home cd $(JAVA_CWD);HOME=$(JAVA_PEP_HOME_DIR) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestMain compile: $(JAVA_CLASSES) diff --git a/test/java/foundation/pEp/jniadapter/test/jni92/SyncCallbacks.java b/test/java/foundation/pEp/jniadapter/test/jni92/SyncCallbacks.java deleted file mode 100644 index 69fe067..0000000 --- a/test/java/foundation/pEp/jniadapter/test/jni92/SyncCallbacks.java +++ /dev/null @@ -1,24 +0,0 @@ -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(""); - } -} \ No newline at end of file diff --git a/test/java/foundation/pEp/jniadapter/test/jni92/TestMain.java b/test/java/foundation/pEp/jniadapter/test/jni92/TestMain.java index 8caee4f..04eab30 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni92/TestMain.java +++ b/test/java/foundation/pEp/jniadapter/test/jni92/TestMain.java @@ -1,5 +1,6 @@ package foundation.pEp.jniadapter.test.jni92; -import foundation.pEp.jniadapter.test.utils.TestUtils; +import foundation.pEp.jniadapter.test.utils.*; +import foundation.pEp.jniadapter.test.framework.*; import foundation.pEp.jniadapter.*; import java.lang.Thread; @@ -24,7 +25,7 @@ class TestThread extends Thread { } public void run() { - TestUtils.logH1( "Thread Starting"); + TestLogger.logH1( "Thread Starting"); TestMain.TestMainRun(nrEngines, useSharedEngines); } } @@ -35,9 +36,9 @@ class TestMain { public static Engine createNewEngine() throws pEpException { Engine e; - TestUtils.logH2("Creating new Engine"); + TestLogger.logH2("Creating new Engine"); e = new Engine(); - TestUtils.log("Engine created with java object ID: " + e.getId()); + TestLogger.log("Engine created with java object ID: " + e.getId()); return e; } @@ -51,7 +52,7 @@ class TestMain { public static void engineConsumer(Vector ev, Consumer ec) { ev.forEach(e -> { - TestUtils.logH2("engineConsumer: on engine java object ID: " + e.getId()); + TestLogger.logH2("engineConsumer: on engine java object ID: " + e.getId()); ec.accept(e); }); } @@ -60,9 +61,9 @@ class TestMain { Consumer c = (e) -> { Vector v = e.own_identities_retrieve(); - TestUtils.log("own idents: " + v.size()); + TestLogger.log("own idents: " + v.size()); v.forEach( i -> { - TestUtils.log(TestUtils.identityToString(i, true)); + TestLogger.log(AdapterTestUtils.identityToString(i, true)); }); e.getVersion(); e.OpenPGP_list_keyinfo(""); @@ -77,8 +78,8 @@ class TestMain { } public static void main(String[] args) { - TestUtils.logH1("JNI-92 Starting"); - TestUtils.setLoggingEnabled(false); + TestLogger.logH1("JNI-92 Starting"); + TestLogger.setLoggingEnabled(false); int nrTestruns = 1000; boolean multiThreaded = true; boolean useSharedEngines = true; @@ -90,7 +91,7 @@ class TestMain { } for (int run = 0; run < nrTestruns; run++ ) { - TestUtils.logH1("Testrun Nr: " + run); + TestLogger.logH1("Testrun Nr: " + run); if (!multiThreaded) { // Single Threaded TestMainRun(nrEnginesPerThread, useSharedEngines); @@ -109,11 +110,11 @@ class TestMain { try { t.join(); } catch (Exception e) { - TestUtils.log("Exception joining thread" + e.toString()); + TestLogger.log("Exception joining thread" + e.toString()); } }); } - TestUtils.logH1("Testrun DONE" ); + TestLogger.logH1("Testrun DONE" ); System.gc(); // TestUtils.sleep(2000); } diff --git a/test/java/foundation/pEp/jniadapter/test/jni94/Makefile b/test/java/foundation/pEp/jniadapter/test/jni94/Makefile index e628c5f..5c221d6 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni94/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/jni94/Makefile @@ -5,14 +5,15 @@ TEST_UNIT_NAME=jni94 JAVA_CLASSES = \ TestMain.class \ - ../utils/TestUtils.class + +JAVA_CLASSES += $(JAVA_CLASSES_FRAMEWORK) .PHONY: compile run test clean all: compile $(MAKE) run -run: compile +run: compile clean-pep-home cd $(JAVA_CWD);HOME=$(JAVA_PEP_HOME_DIR) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestMain compile: $(JAVA_CLASSES) diff --git a/test/java/foundation/pEp/jniadapter/test/jni94/TestMain.java b/test/java/foundation/pEp/jniadapter/test/jni94/TestMain.java index a29e7a9..bae1469 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni94/TestMain.java +++ b/test/java/foundation/pEp/jniadapter/test/jni94/TestMain.java @@ -1,9 +1,7 @@ package foundation.pEp.jniadapter.test.jni94; +import foundation.pEp.jniadapter.test.framework.*; import foundation.pEp.jniadapter.*; -import foundation.pEp.jniadapter.test.utils.TestUtils; - -import java.lang.Thread; - +import foundation.pEp.jniadapter.test.utils.AdapterBaseTestContext; /* This test tries to use the feature described in in JNI-94 @@ -15,21 +13,16 @@ https://pep.foundation/jira/browse/JNI-94 class TestMain { public static void main(String[] args) { - Engine engine; - try { - TestUtils.logH2("Creating new Engine"); - engine = new Engine(); + new TestUnit("JNI-94", new AdapterBaseTestContext(), ctx -> { + TestLogger.logH2("Creating new Engine"); + ctx.engine = new Engine(); Sync.DefaultCallback callbacks = new Sync.DefaultCallback(); - engine.setMessageToSendCallback(callbacks); - TestUtils.logH2("Machine directory: "); - TestUtils.log(engine.getMachineDirectory()); - - TestUtils.logH2("User directory:" ); - TestUtils.log(engine.getUserDirectory()); - } - catch (pEpException ex) { - System.out.println("Cannot load"); - return; - } + ctx.engine.setMessageToSendCallback(callbacks); + TestLogger.logH2("Machine directory: "); + TestLogger.log(ctx.engine.getMachineDirectory()); + + TestLogger.logH2("User directory:" ); + TestLogger.log(ctx.engine.getUserDirectory()); + }).run(); } } diff --git a/test/java/foundation/pEp/jniadapter/test/jni98/Makefile b/test/java/foundation/pEp/jniadapter/test/jni98/Makefile index c749ef7..6f1e518 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni98/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/jni98/Makefile @@ -5,7 +5,9 @@ TEST_UNIT_NAME=jni98 JAVA_CLASSES = \ TestMain.class \ - ../utils/TestUtils.class + ../utils/AdapterTestUtils.class + +JAVA_CLASSES += $(JAVA_CLASSES_FRAMEWORK) .PHONY: compile run test clean diff --git a/test/java/foundation/pEp/jniadapter/test/jni98/TestMain.java b/test/java/foundation/pEp/jniadapter/test/jni98/TestMain.java index 129b6a0..283b101 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni98/TestMain.java +++ b/test/java/foundation/pEp/jniadapter/test/jni98/TestMain.java @@ -1,6 +1,7 @@ package foundation.pEp.jniadapter.test.jni98; -import static foundation.pEp.jniadapter.test.utils.TestUtils.*; +import static foundation.pEp.jniadapter.test.framework.TestLogger.*; +import static foundation.pEp.jniadapter.test.utils.AdapterTestUtils.*; import foundation.pEp.jniadapter.*; import java.nio.file.Files; diff --git a/test/java/foundation/pEp/jniadapter/test/regression/Makefile b/test/java/foundation/pEp/jniadapter/test/regression/Makefile index 526525d..b92525c 100644 --- a/test/java/foundation/pEp/jniadapter/test/regression/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/regression/Makefile @@ -5,14 +5,16 @@ TEST_UNIT_NAME=regression JAVA_CLASSES = \ TestMain.class \ - ../utils/TestUtils.class + ../utils/AdapterBaseTestContext.class + +JAVA_CLASSES += $(JAVA_CLASSES_FRAMEWORK) .PHONY: compile run test clean all: compile $(MAKE) run -run: compile +run: compile clean-pep-home cd $(JAVA_CWD);pwd;HOME=$(JAVA_PEP_HOME_DIR) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestMain compile: $(JAVA_CLASSES) diff --git a/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java b/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java index 61da17e..5133bd7 100644 --- a/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java +++ b/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java @@ -1,336 +1,263 @@ package foundation.pEp.jniadapter.test.regression; - -import foundation.pEp.jniadapter.test.utils.TestUtils; +import foundation.pEp.jniadapter.test.framework.*; +import foundation.pEp.jniadapter.test.utils.*; import foundation.pEp.jniadapter.*; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Vector; -import java.util.function.Consumer; - - -/* -This test is just only checking for unsatisfiedLinkExceptions to make sure all the native calls are implemented -*/ - -class TestEnv { - public Sync.DefaultCallback cb = new Sync.DefaultCallback(); - public Identity alice = new Identity(); - public Identity bob = new Identity(); - public Message msgToSelf; - public Message msgToBob; - public Vector vID = new Vector(); - public Vector vStr = new Vector(); - public byte[] key; - private String fileName = "../resources/test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc"; - public Engine engine = new Engine(); - - public TestEnv() throws Exception { - alice.user_id = "23"; - alice.address = "alice@peptest.org"; - alice.me = true; - - bob.user_id = "42"; - bob.address = "bob@peptest.org"; - - msgToSelf = makeNewMessage(alice, alice, Message.Direction.Outgoing); - msgToBob = makeNewMessage(alice, bob, Message.Direction.Outgoing); - - vID.add(bob); - vStr.add("StringItem"); - - try { - Path path = Paths.get(fileName); - key = Files.readAllBytes(path); - } catch (Exception e) { - TestUtils.log("Could not open key file:" + fileName); - throw e; - } - } - - public static Message makeNewMessage(Identity from, Identity to, Message.Direction dir) { - Message msg = new Message(); - Vector vID = new Vector(); - vID.add(to); - - msg.setFrom(from); - msg.setTo(vID); - msg.setDir(dir); - msg.setLongmsg("Hi i am the message longmsg"); - return msg; - } -} - -class TestUnit { - TestEnv env; - String testUnitName = "default test unit"; - Consumer lambda; - - public TestUnit(String name, Consumer consumer) throws Exception { - testUnitName = name; - lambda = consumer; - env = new TestEnv(); - - } +class RegTestContext extends AdapterBaseTestContext { + // enhance the context - public void run() { - TestUtils.logH1(testUnitName); - try { - lambda.accept(env); - } catch (Throwable e) { - TestUtils.logH1("TestUnit FAILED: " + e.toString()); - return; - } - TestUtils.logH2("SUCCESS!"); + @Override + public void init() throws Exception { + super.init(); + // init the enhancements } } - class TestMain { - public static void main(String[] args) throws Exception { - testRunNew(); - } - - public static void testRunNew() throws Exception { - new TestUnit("Engine.myself", env -> { - env.alice = env.engine.myself(env.alice); + new TestUnit("Engine.myself", new RegTestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); }).run(); - new TestUnit("Engine.encrypt_message", env -> { - env.engine.encrypt_message(env.msgToBob, null, Message.EncFormat.PEP); + new TestUnit("Engine.encrypt_message", new RegTestContext(), ctx -> { + ctx.engine.encrypt_message(ctx.msgToBob, null, Message.EncFormat.PEP); }).run(); - new TestUnit("Engine.encrypt_message_and_add_priv_key", env -> { - env.alice = env.engine.myself(env.alice); - env.engine.encrypt_message_and_add_priv_key(env.msgToSelf, env.alice.fpr); + new TestUnit("Engine.encrypt_message_and_add_priv_key", new RegTestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + ctx.engine.encrypt_message_and_add_priv_key(ctx.msgToSelf, ctx.alice.fpr); }).run(); - new TestUnit("Engine.encrypt_message_for_self", env -> { - env.alice = env.engine.myself(env.alice); - env.engine.encrypt_message_for_self(env.alice, env.msgToSelf, null); + new TestUnit("Engine.encrypt_message_for_self", new RegTestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + ctx.engine.encrypt_message_for_self(ctx.alice, ctx.msgToSelf, null); }).run(); - new TestUnit("Engine.decrypt_message", env -> { - env.engine.decrypt_message(env.msgToSelf, env.vStr, 0); + new TestUnit("Engine.decrypt_message", new RegTestContext(), ctx -> { + ctx.engine.decrypt_message(ctx.msgToSelf, ctx.vStr, 0); }).run(); //TODO: Coredump -// new TestUnit("Engine.re_evaluate_message_rating", env -> { -// env.alice = env.engine.myself(env.alice); -// env.bob = env.engine.myself(env.bob); -// Message msg = env.engine.encrypt_message(env.msgToBob,null, Message.EncFormat.PEP); -// env.engine.re_evaluate_message_rating(msg); +// new TestUnit("Engine.re_evaluate_message_rating", new RegTestContext(), ctx -> { +// ctx.alice = ctx.engine.myself(ctx.alice); +// ctx.bob = ctx.engine.myself(ctx.bob); +// Message msg = ctx.engine.encrypt_message(ctx.msgToBob,null, Message.EncFormat.PEP); +// ctx.engine.re_evaluate_message_rating(msg); // }).run(); - new TestUnit("Engine.outgoing_message_rating", env -> { - env.engine.outgoing_message_rating(env.msgToBob); + new TestUnit("Engine.outgoing_message_rating", new RegTestContext(), ctx -> { + ctx.engine.outgoing_message_rating(ctx.msgToBob); }).run(); - new TestUnit("Engine.outgoing_message_rating_preview", env -> { - env.engine.outgoing_message_rating_preview(env.msgToBob); + new TestUnit("Engine.outgoing_message_rating_preview", new RegTestContext(), ctx -> { + ctx.engine.outgoing_message_rating_preview(ctx.msgToBob); }).run(); - new TestUnit("Engine.get_identity", env -> { - env.alice = env.engine.myself(env.alice); - env.engine.get_identity(env.alice.address, env.alice.user_id); + new TestUnit("Engine.get_identity", new RegTestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + ctx.engine.get_identity(ctx.alice.address, ctx.alice.user_id); }).run(); - new TestUnit("Engine.identity_rating", env -> { - env.alice = env.engine.myself(env.alice); - env.engine.identity_rating(env.alice); + new TestUnit("Engine.identity_rating", new RegTestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + ctx.engine.identity_rating(ctx.alice); }).run(); - new TestUnit("Engine.blacklist_retrieve", env -> { - env.engine.blacklist_retrieve(); + new TestUnit("Engine.blacklist_retrieve", new RegTestContext(), ctx -> { + ctx.engine.blacklist_retrieve(); }).run(); //FAIL - new TestUnit("Engine.own_message_private_key_details", env -> { - env.alice = env.engine.myself(env.alice); - env.bob = env.engine.myself(env.bob); + new TestUnit("Engine.own_message_private_key_details", new RegTestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + ctx.bob = ctx.engine.myself(ctx.bob); - env.engine.encrypt_message(env.msgToBob,null, Message.EncFormat.PEP); - env.engine.own_message_private_key_details(env.msgToBob); + ctx.engine.encrypt_message(ctx.msgToBob, null, Message.EncFormat.PEP); + ctx.engine.own_message_private_key_details(ctx.msgToBob); }).run(); - new TestUnit("Engine.OpenPGP_list_keyinfo", env -> { - env.engine.OpenPGP_list_keyinfo(""); + new TestUnit("Engine.OpenPGP_list_keyinfo", new RegTestContext(), ctx -> { + ctx.engine.OpenPGP_list_keyinfo(""); }).run(); - new TestUnit("Engine.set_identity_flags", env -> { - env.engine.set_identity_flags(env.alice, 0); + new TestUnit("Engine.set_identity_flags", new RegTestContext(), ctx -> { + ctx.engine.set_identity_flags(ctx.alice, 0); }).run(); - new TestUnit("Engine.unset_identity_flags", env -> { - env.engine.unset_identity_flags(env.alice, 0); + new TestUnit("Engine.unset_identity_flags", new RegTestContext(), ctx -> { + ctx.engine.unset_identity_flags(ctx.alice, 0); }).run(); - new TestUnit("Engine.own_identities_retrieve", env -> { - env.engine.own_identities_retrieve(); + new TestUnit("Engine.own_identities_retrieve", new RegTestContext(), ctx -> { + ctx.engine.own_identities_retrieve(); }).run(); - new TestUnit("Engine.get_trustwords", env -> { - env.alice = env.engine.myself(env.alice); - env.bob = env.engine.myself(env.bob); - env.engine.get_trustwords(env.alice, env.bob, "en", false); + new TestUnit("Engine.get_trustwords", new RegTestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + ctx.bob = ctx.engine.myself(ctx.bob); + ctx.engine.get_trustwords(ctx.alice, ctx.bob, "en", false); }).run(); - new TestUnit("Engine.get_trustwords_for_fprs", env -> { - env.alice = env.engine.myself(env.alice); - env.bob = env.engine.myself(env.bob); + new TestUnit("Engine.get_trustwords_for_fprs", new RegTestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + ctx.bob = ctx.engine.myself(ctx.bob); - env.engine.get_trustwords_for_fprs(env.alice.fpr, env.bob.fpr, "en", false); + ctx.engine.get_trustwords_for_fprs(ctx.alice.fpr, ctx.bob.fpr, "en", false); }).run(); - new TestUnit("Engine.get_message_trustwords", env -> { - env.engine.get_message_trustwords(env.msgToBob, null, env.bob, "en", false); + new TestUnit("Engine.get_message_trustwords", new RegTestContext(), ctx -> { + ctx.engine.get_message_trustwords(ctx.msgToBob, null, ctx.bob, "en", false); }).run(); - new TestUnit("Engine.get_languagelist", env -> { - env.engine.get_languagelist(); + new TestUnit("Engine.get_languagelist", new RegTestContext(), ctx -> { + ctx.engine.get_languagelist(); }).run(); - new TestUnit("Engine.key_reset_trust", env -> { - env.alice = env.engine.myself(env.alice); - env.engine.key_reset_trust(env.alice); + new TestUnit("Engine.key_reset_trust", new RegTestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + ctx.engine.key_reset_trust(ctx.alice); }).run(); - new TestUnit("Engine.key_reset_identity", env -> { - env.alice = env.engine.myself(env.alice); - env.engine.key_reset_identity(env.alice, ""); + new TestUnit("Engine.key_reset_identity", new RegTestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + ctx.engine.key_reset_identity(ctx.alice, ""); }).run(); - new TestUnit("Engine.key_reset_user", env -> { - env.alice = env.engine.myself(env.alice); - env.engine.key_reset_user("fsdjugsh", env.alice.fpr); + new TestUnit("Engine.key_reset_user", new RegTestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + ctx.engine.key_reset_user("fsdjugsh", ctx.alice.fpr); }).run(); - new TestUnit("Engine.key_reset_all_own_keys", env -> { - env.engine.key_reset_all_own_keys(); + new TestUnit("Engine.key_reset_all_own_keys", new RegTestContext(), ctx -> { + ctx.engine.key_reset_all_own_keys(); }).run(); - new TestUnit("Engine.deliverHandshakeResult", env -> { - env.engine.deliverHandshakeResult(SyncHandshakeResult.SyncHandshakeCancel, env.vID); + new TestUnit("Engine.deliverHandshakeResult", new RegTestContext(), ctx -> { + ctx.engine.deliverHandshakeResult(SyncHandshakeResult.SyncHandshakeCancel, ctx.vID); }).run(); - new TestUnit("Engine.leave_device_group", env -> { - env.engine.startSync(); - env.engine.leave_device_group(); - }).run(); - new TestUnit("Engine.enable_identity_for_sync", env -> { - env.alice = env.engine.myself(env.alice); - env.engine.enable_identity_for_sync(env.alice); + //[17:51] < heck> | this one fails since: 4665:f067c9e95455 + //[17:52] < heck> | i confirmed it still works in the parent revision 4662:71147c43e31b + //[17:52] < heck> | the error i get is: + //[17:53] < heck> | *** send message KeySync Beacon service KeySync_fsm.c:234 + //[17:53] < heck> | Assertion failed: (msg->from && msg->from->fpr), function attach_own_key, file message_api.c, line 1581. + +// new TestUnit("Engine.leave_device_group", new RegTestContext(), ctx -> { +// ctx.engine.startSync(); +// ctx.engine.leave_device_group(); +// }).run(); + + new TestUnit("Engine.enable_identity_for_sync", new RegTestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + ctx.engine.enable_identity_for_sync(ctx.alice); }).run(); - new TestUnit("Engine.disable_identity_for_sync", env -> { - env.alice = env.engine.myself(env.alice); - env.engine.disable_identity_for_sync(env.alice); + new TestUnit("Engine.disable_identity_for_sync", new RegTestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + ctx.engine.disable_identity_for_sync(ctx.alice); }).run(); // TODO: class not found: foundation/pEp/jniadapter/Message$CipherSuite -// new TestUnit("Engine.config_cipher_suite", env -> { -// env.engine.config_cipher_suite(CipherSuite.pEpCipherSuiteDefault); +// new TestUnit("Engine.config_cipher_suite", new RegTestContext(), ctx -> { +// ctx.engine.config_cipher_suite(CipherSuite.pEpCipherSuiteDefault); // }).run(); - new TestUnit("Engine.trustwords", env -> { - env.engine.trustwords(env.alice); + new TestUnit("Engine.trustwords", new RegTestContext(), ctx -> { + ctx.engine.trustwords(ctx.alice); }).run(); - new TestUnit("Engine.updateIdentity", env -> { - env.engine.updateIdentity(env.alice); + new TestUnit("Engine.updateIdentity", new RegTestContext(), ctx -> { + ctx.engine.updateIdentity(ctx.alice); }).run(); - new TestUnit("Engine.setOwnKey", env -> { - env.alice = env.engine.myself(env.alice); - env.engine.setOwnKey(env.alice, env.alice.fpr); + new TestUnit("Engine.setOwnKey", new RegTestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + ctx.engine.setOwnKey(ctx.alice, ctx.alice.fpr); }).run(); - new TestUnit("Engine.keyMistrusted", env -> { - env.alice = env.engine.myself(env.alice); - env.engine.keyMistrusted(env.alice); + new TestUnit("Engine.keyMistrusted", new RegTestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + ctx.engine.keyMistrusted(ctx.alice); }).run(); - new TestUnit("Engine.keyResetTrust", env -> { - env.engine.keyResetTrust(env.alice); + new TestUnit("Engine.keyResetTrust", new RegTestContext(), ctx -> { + ctx.engine.keyResetTrust(ctx.alice); }).run(); - new TestUnit("Engine.trustPersonalKey", env -> { - env.engine.trustPersonalKey(env.alice); + new TestUnit("Engine.trustPersonalKey", new RegTestContext(), ctx -> { + ctx.engine.trustPersonalKey(ctx.alice); }).run(); - new TestUnit("Engine.trustOwnKey", env -> { - env.alice = env.engine.myself(env.alice); - env.engine.trustOwnKey(env.alice); + new TestUnit("Engine.trustOwnKey", new RegTestContext(), ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + ctx.engine.trustOwnKey(ctx.alice); }).run(); - new TestUnit("Engine.importKey", env -> { - env.engine.importKey(env.key); + new TestUnit("Engine.importKey", new RegTestContext(), ctx -> { + ctx.engine.importKey(ctx.key); }).run(); - new TestUnit("Engine.blacklist_add", env -> { - env.engine.blacklist_add("43"); + new TestUnit("Engine.blacklist_add", new RegTestContext(), ctx -> { + ctx.engine.blacklist_add("43"); }).run(); - new TestUnit("Engine.blacklist_delete", env -> { - env.engine.blacklist_delete("43"); + new TestUnit("Engine.blacklist_delete", new RegTestContext(), ctx -> { + ctx.engine.blacklist_delete("43"); }).run(); - new TestUnit("Engine.blacklist_is_listed", env -> { - env.engine.blacklist_is_listed("43"); + new TestUnit("Engine.blacklist_is_listed", new RegTestContext(), ctx -> { + ctx.engine.blacklist_is_listed("43"); }).run(); - new TestUnit("Engine.config_passive_mode", env -> { - env.engine.config_passive_mode(false); + new TestUnit("Engine.config_passive_mode", new RegTestContext(), ctx -> { + ctx.engine.config_passive_mode(false); }).run(); - new TestUnit("Engine.config_unencrypted_subject", env -> { - env.engine.config_unencrypted_subject(false); + new TestUnit("Engine.config_unencrypted_subject", new RegTestContext(), ctx -> { + ctx.engine.config_unencrypted_subject(false); }).run(); - new TestUnit("Engine.getCrashdumpLog", env -> { - env.engine.getCrashdumpLog(0); + new TestUnit("Engine.getCrashdumpLog", new RegTestContext(), ctx -> { + ctx.engine.getCrashdumpLog(0); }).run(); -// new TestUnit("Engine.getUserDirectory", env -> { -// env.engine.getUserDirectory(); -// }).run(); + new TestUnit("Engine.getUserDirectory", new RegTestContext(), ctx -> { + ctx.engine.getUserDirectory(); + }).run(); -// new TestUnit("Engine.getMachineDirectory", env -> { -// env.engine.getMachineDirectory(); -// }).run(); + new TestUnit("Engine.getMachineDirectory", new RegTestContext(), ctx -> { + ctx.engine.getMachineDirectory(); + }).run(); // AbstractEngine.java - new TestUnit("Engine.close", env -> { - env.engine.close(); + new TestUnit("Engine.close", new RegTestContext(), ctx -> { + ctx.engine.close(); }).run(); - new TestUnit("Engine.getVersion", env -> { - env.engine.getVersion(); + new TestUnit("Engine.getVersion", new RegTestContext(), ctx -> { + ctx.engine.getVersion(); }).run(); - new TestUnit("Engine.getProtocolVersion", env -> { - env.engine.getProtocolVersion(); + new TestUnit("Engine.getProtocolVersion", new RegTestContext(), ctx -> { + ctx.engine.getProtocolVersion(); }).run(); - new TestUnit("Engine.startKeyserverLookup", env -> { - env.engine.startKeyserverLookup(); + new TestUnit("Engine.startKeyserverLookup", new RegTestContext(), ctx -> { + ctx.engine.startKeyserverLookup(); }).run(); - new TestUnit("Engine.startSync", env -> { - env.engine.startSync(); + new TestUnit("Engine.startSync", new RegTestContext(), ctx -> { + ctx.engine.startSync(); }).run(); - new TestUnit("Engine.stopSync", env -> { - env.engine.stopSync(); + new TestUnit("Engine.stopSync", new RegTestContext(), ctx -> { + ctx.engine.stopSync(); }).run(); - new TestUnit("Engine.isSyncRunning", env -> { - env.engine.isSyncRunning(); + new TestUnit("Engine.isSyncRunning", new RegTestContext(), ctx -> { + ctx.engine.isSyncRunning(); }).run(); - } } diff --git a/test/java/foundation/pEp/jniadapter/test/jni85/Makefile b/test/java/foundation/pEp/jniadapter/test/templateAlice/Makefile similarity index 61% rename from test/java/foundation/pEp/jniadapter/test/jni85/Makefile rename to test/java/foundation/pEp/jniadapter/test/templateAlice/Makefile index f8e455b..c02d07f 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni85/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/templateAlice/Makefile @@ -1,20 +1,20 @@ include ../../../../../../../Makefile.conf include ../Makefile.conf -TEST_UNIT_NAME=jni85 +TEST_UNIT_NAME=templateAlice JAVA_CLASSES = \ - Step1.class \ - Step2.class \ - ../utils/TestUtils.class + TestMain.class + +JAVA_CLASSES += $(JAVA_CLASSES_FRAMEWORK) .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 +run: compile clean-pep-home + cd $(JAVA_CWD);pwd;HOME=$(JAVA_PEP_HOME_DIR) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestMain compile: $(JAVA_CLASSES) diff --git a/test/java/foundation/pEp/jniadapter/test/templateAlice/TestMain.java b/test/java/foundation/pEp/jniadapter/test/templateAlice/TestMain.java new file mode 100644 index 0000000..0a8a847 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/templateAlice/TestMain.java @@ -0,0 +1,21 @@ +package foundation.pEp.jniadapter.test.templateAlice; +import foundation.pEp.jniadapter.test.framework.*; +import foundation.pEp.jniadapter.test.utils.AdapterBaseTestContext; + + +class TestMain { + public static void main(String[] args) throws Exception { + new TestUnit("Test Template",new AdapterBaseTestContext() , ctx -> { + // do stuff using the context + // Test FAILS on unhandled exception, otherwise SUCCESS + + ctx.alice = ctx.engine.myself(ctx.alice); + + if(ctx.alice.fpr == null) { + throw new RuntimeException(); + } + }).run(); + } +} + + diff --git a/test/java/foundation/pEp/jniadapter/test/templateAliceBob/Makefile b/test/java/foundation/pEp/jniadapter/test/templateAliceBob/Makefile new file mode 100644 index 0000000..c02d07f --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/templateAliceBob/Makefile @@ -0,0 +1,33 @@ +include ../../../../../../../Makefile.conf +include ../Makefile.conf + +TEST_UNIT_NAME=templateAlice + +JAVA_CLASSES = \ + TestMain.class + +JAVA_CLASSES += $(JAVA_CLASSES_FRAMEWORK) + +.PHONY: compile run test clean + +all: compile + $(MAKE) run + +run: compile clean-pep-home + cd $(JAVA_CWD);pwd;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 \ No newline at end of file diff --git a/test/java/foundation/pEp/jniadapter/test/templateAliceBob/TestMain.java b/test/java/foundation/pEp/jniadapter/test/templateAliceBob/TestMain.java new file mode 100644 index 0000000..5866b96 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/templateAliceBob/TestMain.java @@ -0,0 +1,21 @@ +package foundation.pEp.jniadapter.test.templateAliceBob; +import foundation.pEp.jniadapter.test.framework.*; +import foundation.pEp.jniadapter.test.utils.AdapterBaseTestContext; + + +class TestMain { + public static void main(String[] args) throws Exception { + new TestUnit("Test Template",new AdapterBaseTestContext() , ctx -> { + // do stuff using the context + // Test FAILS on unhandled exception, otherwise SUCCESS + + ctx.alice = ctx.engine.myself(ctx.alice); + + if(ctx.alice.fpr == null) { + throw new RuntimeException(); + } + }).run(); + } +} + + diff --git a/test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java b/test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java new file mode 100644 index 0000000..e8d5100 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java @@ -0,0 +1,105 @@ +package foundation.pEp.jniadapter.test.utils; +import foundation.pEp.jniadapter.test.framework.*; +import foundation.pEp.jniadapter.*; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Vector; + +public class AdapterBaseTestContext implements AbstractTestContext { + public Sync.DefaultCallback cb = new Sync.DefaultCallback(); + public Identity alice; + public Identity bob; + public Message msgToSelf; + public Message msgToBob; + public Vector vID; + public Vector vStr; + public byte[] key; + private String fileName = "../resources/test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc"; + public Engine engine; + + public AdapterBaseTestContext() { } + + public void init() throws Exception { + vID = new Vector(); + vStr = new Vector(); + + engine = new Engine(); + + alice = new Identity(); + alice.user_id = "23"; + alice.address = "alice@peptest.org"; + alice.me = true; + + bob = new Identity(); + bob.user_id = "42"; + bob.address = "bob@peptest.org"; + + msgToSelf = AdapterTestUtils.makeNewTestMessage(alice, alice, Message.Direction.Outgoing); + msgToBob = AdapterTestUtils.makeNewTestMessage(alice, bob, Message.Direction.Outgoing); + + vID.add(bob); + vStr.add("StringItem"); + + try { + Path path = Paths.get(fileName); + key = Files.readAllBytes(path); + } catch (Exception e) { + TestLogger.log("Could not open key file:" + fileName); + throw e; + } + } +} + + +/*package foundation.pEp.jniadapter.test.framework; +import foundation.pEp.jniadapter.test.utils.*; +import foundation.pEp.jniadapter.*; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Vector; + +public class TestContext { + public TestCallbacks cb = new TestCallbacks(); + public Identity alice; + public Identity bob; + public Message msgToSelf; + public Message msgToBob; + public Vector vID; + public Vector vStr; + public byte[] key; + private String fileName = "../resources/test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc"; + public Engine engine; + + public TestContext() { + } + + public void init() throws Exception { + this.vID = new Vector(); + this.vStr = new Vector(); + this.engine = new Engine(); + this.alice = new Identity(); + this.alice.user_id = "23"; + this.alice.address = "alice@peptest.org"; + this.alice.me = true; + this.bob = new Identity(); + this.bob.user_id = "42"; + this.bob.address = "bob@peptest.org"; + this.msgToSelf = AdapterTestUtils.makeNewTestMessage(this.alice, this.alice, Message.Direction.Outgoing); + this.msgToBob = AdapterTestUtils.makeNewTestMessage(this.alice, this.bob, Message.Direction.Outgoing); + this.vID.add(this.bob); + this.vStr.add("StringItem"); + + try { + Path var1 = Paths.get(this.fileName); + this.key = Files.readAllBytes(var1); + } catch (Exception var2) { + TestLogger.log("Could not open key file:" + this.fileName); + throw var2; + } + } +} +*/ \ No newline at end of file diff --git a/test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java b/test/java/foundation/pEp/jniadapter/test/utils/AdapterTestUtils.java similarity index 84% rename from test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java rename to test/java/foundation/pEp/jniadapter/test/utils/AdapterTestUtils.java index b0f2b63..371e41f 100644 --- a/test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java +++ b/test/java/foundation/pEp/jniadapter/test/utils/AdapterTestUtils.java @@ -1,24 +1,13 @@ package foundation.pEp.jniadapter.test.utils; - import foundation.pEp.jniadapter.*; import java.util.ArrayList; import java.util.Vector; -public class TestUtils { - - - public static void sleep(int mSec) { - try { - Thread.sleep(mSec); - } catch (InterruptedException ex) { - System.out.println("sleep got interrupted"); - } - } - +public class AdapterTestUtils { public static String identityToString(Identity i, Boolean full) { String ret = ""; - if (full) { + if(full) { ret += "address: " + i.address + "\n"; ret += "fpr: " + i.fpr + "\n"; ret += "username: " + i.username + "\n"; @@ -34,6 +23,7 @@ public class TestUtils { return ret; } + public static String msgToString(Message msg, boolean full) { String ret = ""; ArrayList> kvs = new ArrayList<>(); @@ -287,45 +277,16 @@ public class TestUtils { } return spv; } - // ------------------------ Logging ------------------------ - - private static boolean logEnabled = true; - - public static void setLoggingEnabled(boolean enabled) { - logEnabled = enabled; - } - public static boolean isLoggingEnabled() { - return logEnabled; - } - - public static void log(String msg) { - if (logEnabled) { - String threadNameFmt = String.format("%-10s", Thread.currentThread().getName()); - String msgOut = threadNameFmt + ": " + msg; - System.out.println(msgOut); - } - } - - public static void logH1(String msg) { - log(getDecoratedString(msg, "=")); - } - - public static void logH2(String msg) { - log(getDecoratedString(msg, "-")); - } - - private static String getDecoratedString(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 + " " + msg + " " + decorationStr; - } + public static Message makeNewTestMessage(Identity from, Identity to, Message.Direction dir) { + Message msg = new Message(); + Vector vID = new Vector(); + vID.add(to); - public static void logSectEnd(String msg) { - log(msg + "\n"); + msg.setFrom(from); + msg.setTo(vID); + msg.setDir(dir); + msg.setLongmsg("Hi i am the message longmsg"); + return msg; } } \ No newline at end of file diff --git a/test/java/foundation/pEp/jniadapter/test/utils/TestCallbacks.java b/test/java/foundation/pEp/jniadapter/test/utils/TestCallbacks.java new file mode 100644 index 0000000..15ab223 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/utils/TestCallbacks.java @@ -0,0 +1,22 @@ +package foundation.pEp.jniadapter.test.utils; +import foundation.pEp.jniadapter.test.framework.*; +import foundation.pEp.jniadapter.*; + +public class TestCallbacks implements Sync.MessageToSendCallback, Sync.NotifyHandshakeCallback { + public void messageToSend(Message message) { + TestLogger.logH1("Message to send called"); + TestLogger.log("From: " + message.getFrom()); + TestLogger.log("To: " + message.getTo()); + TestLogger.log("Subject: " + message.getShortmsg()); + TestLogger.log("Attachement[0]: " + message.getAttachments().get(0).toString()); + } + + public void notifyHandshake(Identity myself, Identity partner, SyncHandshakeSignal signal) { + TestLogger.logH1("Notify handshake called"); + TestLogger.log("myself: " + AdapterTestUtils.identityToString(myself, false)); + TestLogger.log("Partner: " + AdapterTestUtils.identityToString(partner, false)); + TestLogger.log("Signal: " + signal); + } +} + + diff --git a/test/resources/pep-home/.dontdeleteme b/test/resources/per-user-dirs/.dontdeleteme similarity index 100% rename from test/resources/pep-home/.dontdeleteme rename to test/resources/per-user-dirs/.dontdeleteme