From 78a7ad7826458820f7e0b5a8ced69bc049dc8972 Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 7 May 2020 01:17:33 +0200 Subject: [PATCH 01/12] Generally clean PER_USER_DIRECTORY (.pEp) before every testrun. --- test/java/foundation/pEp/jniadapter/test/basic/Makefile | 2 +- test/java/foundation/pEp/jniadapter/test/jni85/Makefile | 2 +- test/java/foundation/pEp/jniadapter/test/jni88/Makefile | 2 +- test/java/foundation/pEp/jniadapter/test/jni91/Makefile | 2 +- test/java/foundation/pEp/jniadapter/test/jni92/Makefile | 2 +- test/java/foundation/pEp/jniadapter/test/jni94/Makefile | 2 +- test/java/foundation/pEp/jniadapter/test/regression/Makefile | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/java/foundation/pEp/jniadapter/test/basic/Makefile b/test/java/foundation/pEp/jniadapter/test/basic/Makefile index 440b729..4d557f0 100644 --- a/test/java/foundation/pEp/jniadapter/test/basic/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/basic/Makefile @@ -13,7 +13,7 @@ JAVA_CLASSES = \ 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/jni85/Makefile b/test/java/foundation/pEp/jniadapter/test/jni85/Makefile index f8e455b..8b96ae7 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni85/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/jni85/Makefile @@ -13,7 +13,7 @@ JAVA_CLASSES = \ 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/jni88/Makefile b/test/java/foundation/pEp/jniadapter/test/jni88/Makefile index 1bd434a..407b9f5 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni88/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/jni88/Makefile @@ -12,7 +12,7 @@ JAVA_CLASSES = \ 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..0035de8 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni91/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/jni91/Makefile @@ -12,7 +12,7 @@ JAVA_CLASSES = \ 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..fac4197 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni92/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/jni92/Makefile @@ -13,7 +13,7 @@ JAVA_CLASSES = \ 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/Makefile b/test/java/foundation/pEp/jniadapter/test/jni94/Makefile index e628c5f..d4cc4b4 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni94/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/jni94/Makefile @@ -12,7 +12,7 @@ JAVA_CLASSES = \ 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/regression/Makefile b/test/java/foundation/pEp/jniadapter/test/regression/Makefile index 526525d..e02cf3a 100644 --- a/test/java/foundation/pEp/jniadapter/test/regression/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/regression/Makefile @@ -12,7 +12,7 @@ JAVA_CLASSES = \ 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) From 03655f22832800fd7e688544c4d3fa147c437593 Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 7 May 2020 02:29:42 +0200 Subject: [PATCH 03/12] Makefiles. More structure. More logging --- Makefile | 24 ++++---------------- Makefile.conf | 61 ++++++++++++++++++++++++++++----------------------- src/Makefile | 13 +++++++++++ 3 files changed, 51 insertions(+), 47 deletions(-) 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 From 96c2484aface26a3d2088b2519f31a89a5ac3c91 Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 7 May 2020 17:32:45 +0200 Subject: [PATCH 04/12] Fix for pEpEngine default branch: mime_encode_messageO()/mime_decode_message() mime_encode_message() "has_pEp_msg_attachment" hard coded to false mime_decode_message() "has_pEp_msg_attachment" hard coded to NULL --- src/gen_cpp_Message.ysl2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gen_cpp_Message.ysl2 b/src/gen_cpp_Message.ysl2 index 2e587de..a5f4496 100644 --- a/src/gen_cpp_Message.ysl2 +++ b/src/gen_cpp_Message.ysl2 @@ -70,7 +70,7 @@ tstylesheet { size_t _size = (size_t) env->GetArrayLength(mime_text); ::«@name» *_msg = nullptr; - PEP_STATUS status = mime_decode_«@name»(_mime_text, _size, &_msg); + PEP_STATUS status = mime_decode_«@name»(_mime_text, _size, &_msg, NULL); if (status) throw_pEp_Exception(env, status); return (jlong) (int64_t) (intptr_t) _msg; @@ -81,7 +81,7 @@ tstylesheet { pEpLog("called"); «@name» *_obj = «@name»_ptr(env, msg); char *mime_text = nullptr; - PEP_STATUS status = ::mime_encode_«@name»(_obj, false, &mime_text); + PEP_STATUS status = ::mime_encode_«@name»(_obj, false, &mime_text, false); if (status) throw_pEp_Exception(env, status); jbyteArray result = from_string(env, mime_text); From ca917573b16f4baa13c415061a5acf5427fc34d5 Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 13 May 2020 17:03:42 +0200 Subject: [PATCH 05/12] Add test framework (extracted) and test template --- .hgignore | 1 + .../test/framework/TestContext.java | 44 +++++++++++++++++++ .../jniadapter/test/framework/TestUnit.java | 28 ++++++++++++ .../pEp/jniadapter/test/template/Makefile | 34 ++++++++++++++ .../jniadapter/test/template/TestMain.java | 14 ++++++ .../pEp/jniadapter/test/utils/TestUtils.java | 12 +++++ 6 files changed, 133 insertions(+) create mode 100644 test/java/foundation/pEp/jniadapter/test/framework/TestContext.java create mode 100644 test/java/foundation/pEp/jniadapter/test/framework/TestUnit.java create mode 100644 test/java/foundation/pEp/jniadapter/test/template/Makefile create mode 100644 test/java/foundation/pEp/jniadapter/test/template/TestMain.java diff --git a/.hgignore b/.hgignore index 1eedcac..2d8e0c5 100644 --- a/.hgignore +++ b/.hgignore @@ -12,6 +12,7 @@ syntax: glob *.orig *~ .DS_Store +*.db # ignore generated files diff --git a/test/java/foundation/pEp/jniadapter/test/framework/TestContext.java b/test/java/foundation/pEp/jniadapter/test/framework/TestContext.java new file mode 100644 index 0000000..6ae9775 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/framework/TestContext.java @@ -0,0 +1,44 @@ +package foundation.pEp.jniadapter.test.framework; +import foundation.pEp.jniadapter.test.utils.TestUtils; +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 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 TestContext() throws Exception { + alice.user_id = "23"; + alice.address = "alice@peptest.org"; + alice.me = true; + + bob.user_id = "42"; + bob.address = "bob@peptest.org"; + + msgToSelf = TestUtils.makeNewTestMessage(alice, alice, Message.Direction.Outgoing); + msgToBob = TestUtils.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) { + TestUtils.log("Could not open key file:" + fileName); + throw e; + } + } +} \ No newline at end of file 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..883707d --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/framework/TestUnit.java @@ -0,0 +1,28 @@ +package foundation.pEp.jniadapter.test.framework; +import foundation.pEp.jniadapter.test.utils.TestUtils; + +import java.util.function.Consumer; + +public class TestUnit { + String testUnitName = "default test unit"; + TestContext ctx; + Consumer lambda; + + public TestUnit(String name, TestContext c, Consumer consumer) throws Exception { + testUnitName = name; + lambda = consumer; + ctx = c; + } + + public void run() { + TestUtils.logH1(testUnitName); + try { + lambda.accept(ctx); + } catch (Throwable e) { + TestUtils.logH1("TestUnit FAILED: " + e.toString()); + return; + } + TestUtils.logH2("SUCCESS!"); + } +} + diff --git a/test/java/foundation/pEp/jniadapter/test/template/Makefile b/test/java/foundation/pEp/jniadapter/test/template/Makefile new file mode 100644 index 0000000..5b3ad94 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/template/Makefile @@ -0,0 +1,34 @@ +include ../../../../../../../Makefile.conf +include ../Makefile.conf + +TEST_UNIT_NAME=template + +JAVA_CLASSES = \ + TestMain.class \ + ../framework/TestUnit.class \ + ../framework/TestContext.class \ + ../utils/TestUtils.class + +.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/template/TestMain.java b/test/java/foundation/pEp/jniadapter/test/template/TestMain.java new file mode 100644 index 0000000..d0e4fe1 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/template/TestMain.java @@ -0,0 +1,14 @@ +package foundation.pEp.jniadapter.test.template; +import foundation.pEp.jniadapter.test.framework.*; +import foundation.pEp.jniadapter.*; + + +class TestMain { + public static void main(String[] args) throws Exception { + new TestUnit("Engine.myself",new TestContext() , ctx -> { + ctx.alice = ctx.engine.myself(ctx.alice); + }).run(); + } +} + + diff --git a/test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java b/test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java index 223c351..332914c 100644 --- a/test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java +++ b/test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java @@ -204,6 +204,18 @@ public class TestUtils { return ret; } + public static Message makeNewTestMessage(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; + } + // ------------------------ Logging ------------------------ private static boolean logEnabled = true; From 9c1afb3a0c21c40c7ed8feae0d614322e08e8e68 Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 13 May 2020 18:18:31 +0200 Subject: [PATCH 06/12] add template to tests Makefile --- test/java/foundation/pEp/jniadapter/test/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/java/foundation/pEp/jniadapter/test/Makefile b/test/java/foundation/pEp/jniadapter/test/Makefile index c5ac816..2b79d27 100644 --- a/test/java/foundation/pEp/jniadapter/test/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/Makefile @@ -3,6 +3,7 @@ all: compile run: compile + $(MAKE) -C template run $(MAKE) -C basic run $(MAKE) -C regression run #BROKEN $(MAKE) -C jni85 run @@ -12,6 +13,7 @@ run: compile $(MAKE) -C jni94 run compile: + $(MAKE) -C template compile $(MAKE) -C basic compile $(MAKE) -C regression compile #BROKEN $(MAKE) -C jni85 compile @@ -21,6 +23,7 @@ compile: $(MAKE) -C jni94 compile clean: + $(MAKE) -C template clean $(MAKE) -C basic clean $(MAKE) -C regression clean $(MAKE) -C jni85 clean From c787ffcec907073fe0d4433930f1329b2a782127 Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 13 May 2020 18:23:40 +0200 Subject: [PATCH 07/12] Changed regression test to use the extracted test.framework pkg. --- .../jniadapter/test/regression/TestMain.java | 360 +++++++----------- 1 file changed, 138 insertions(+), 222 deletions(-) diff --git a/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java b/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java index 61da17e..50323f0 100644 --- a/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java +++ b/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java @@ -1,336 +1,252 @@ package foundation.pEp.jniadapter.test.regression; - -import foundation.pEp.jniadapter.test.utils.TestUtils; +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; -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(); - - } - - public void run() { - TestUtils.logH1(testUnitName); - try { - lambda.accept(env); - } catch (Throwable e) { - TestUtils.logH1("TestUnit FAILED: " + e.toString()); - return; - } - TestUtils.logH2("SUCCESS!"); - } -} - - 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), ctx -> { +// ctx.engine.startSync(); +// ctx.engine.leave_device_group(); +// }).run(); + + new TestUnit("Engine.enable_identity_for_sync", new TestContext(), 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 TestContext(), 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 TestContext(), ctx -> { +// ctx.engine.config_cipher_suite(CipherSuite.pEpCipherSuiteDefault); // }).run(); - new TestUnit("Engine.trustwords", env -> { - env.engine.trustwords(env.alice); + new TestUnit("Engine.trustwords", new TestContext(), ctx -> { + ctx.engine.trustwords(ctx.alice); }).run(); - new TestUnit("Engine.updateIdentity", env -> { - env.engine.updateIdentity(env.alice); + new TestUnit("Engine.updateIdentity", new TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), ctx -> { + ctx.engine.keyResetTrust(ctx.alice); }).run(); - new TestUnit("Engine.trustPersonalKey", env -> { - env.engine.trustPersonalKey(env.alice); + new TestUnit("Engine.trustPersonalKey", new TestContext(), 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 TestContext(), 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 TestContext(), ctx -> { + ctx.engine.importKey(ctx.key); }).run(); - new TestUnit("Engine.blacklist_add", env -> { - env.engine.blacklist_add("43"); + new TestUnit("Engine.blacklist_add", new TestContext(), ctx -> { + ctx.engine.blacklist_add("43"); }).run(); - new TestUnit("Engine.blacklist_delete", env -> { - env.engine.blacklist_delete("43"); + new TestUnit("Engine.blacklist_delete", new TestContext(), 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 TestContext(), 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 TestContext(), 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 TestContext(), ctx -> { + ctx.engine.config_unencrypted_subject(false); }).run(); - new TestUnit("Engine.getCrashdumpLog", env -> { - env.engine.getCrashdumpLog(0); + new TestUnit("Engine.getCrashdumpLog", new TestContext(), ctx -> { + ctx.engine.getCrashdumpLog(0); }).run(); -// new TestUnit("Engine.getUserDirectory", env -> { -// env.engine.getUserDirectory(); -// }).run(); + new TestUnit("Engine.getUserDirectory", new TestContext(), ctx -> { + ctx.engine.getUserDirectory(); + }).run(); -// new TestUnit("Engine.getMachineDirectory", env -> { -// env.engine.getMachineDirectory(); -// }).run(); + new TestUnit("Engine.getMachineDirectory", new TestContext(), ctx -> { + ctx.engine.getMachineDirectory(); + }).run(); // AbstractEngine.java - new TestUnit("Engine.close", env -> { - env.engine.close(); + new TestUnit("Engine.close", new TestContext(), ctx -> { + ctx.engine.close(); }).run(); - new TestUnit("Engine.getVersion", env -> { - env.engine.getVersion(); + new TestUnit("Engine.getVersion", new TestContext(), ctx -> { + ctx.engine.getVersion(); }).run(); - new TestUnit("Engine.getProtocolVersion", env -> { - env.engine.getProtocolVersion(); + new TestUnit("Engine.getProtocolVersion", new TestContext(), ctx -> { + ctx.engine.getProtocolVersion(); }).run(); - new TestUnit("Engine.startKeyserverLookup", env -> { - env.engine.startKeyserverLookup(); + new TestUnit("Engine.startKeyserverLookup", new TestContext(), ctx -> { + ctx.engine.startKeyserverLookup(); }).run(); - new TestUnit("Engine.startSync", env -> { - env.engine.startSync(); + new TestUnit("Engine.startSync", new TestContext(), ctx -> { + ctx.engine.startSync(); }).run(); - new TestUnit("Engine.stopSync", env -> { - env.engine.stopSync(); + new TestUnit("Engine.stopSync", new TestContext(), ctx -> { + ctx.engine.stopSync(); }).run(); - new TestUnit("Engine.isSyncRunning", env -> { - env.engine.isSyncRunning(); + new TestUnit("Engine.isSyncRunning", new TestContext(), ctx -> { + ctx.engine.isSyncRunning(); }).run(); - } } From 07a78b4009e2519dee3756dcfb3dfcd2b1eaa386 Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 13 May 2020 18:31:39 +0200 Subject: [PATCH 08/12] Remove testcase for rejected issue --- .hgignore | 1 + .../foundation/pEp/jniadapter/test/Makefile | 3 - .../pEp/jniadapter/test/jni85/Makefile | 33 ----------- .../pEp/jniadapter/test/jni85/Step1.java | 58 ------------------- .../pEp/jniadapter/test/jni85/Step2.java | 36 ------------ .../jniadapter/test/jni85/SyncCallbacks.java | 25 -------- 6 files changed, 1 insertion(+), 155 deletions(-) delete mode 100644 test/java/foundation/pEp/jniadapter/test/jni85/Makefile delete mode 100644 test/java/foundation/pEp/jniadapter/test/jni85/Step1.java delete mode 100644 test/java/foundation/pEp/jniadapter/test/jni85/Step2.java delete mode 100644 test/java/foundation/pEp/jniadapter/test/jni85/SyncCallbacks.java diff --git a/.hgignore b/.hgignore index 2d8e0c5..d83d981 100644 --- a/.hgignore +++ b/.hgignore @@ -13,6 +13,7 @@ syntax: glob *~ .DS_Store *.db +*.log # ignore generated files diff --git a/test/java/foundation/pEp/jniadapter/test/Makefile b/test/java/foundation/pEp/jniadapter/test/Makefile index 2b79d27..d1eb828 100644 --- a/test/java/foundation/pEp/jniadapter/test/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/Makefile @@ -6,7 +6,6 @@ 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 @@ -16,7 +15,6 @@ 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 @@ -26,7 +24,6 @@ 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/jni85/Makefile b/test/java/foundation/pEp/jniadapter/test/jni85/Makefile deleted file mode 100644 index 8b96ae7..0000000 --- a/test/java/foundation/pEp/jniadapter/test/jni85/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -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 clean-pep-home - 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 \ No newline at end of file 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("================================"); - } -} - From b749bbc0e55453919efeeff31940201eca2e164c Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 14 May 2020 19:03:59 +0200 Subject: [PATCH 09/12] Improve the test framework --- .../pEp/jniadapter/test/basic/TestMain.java | 3 +- .../test/framework/TestContext.java | 21 +++- .../jniadapter/test/framework/TestUnit.java | 9 +- .../jniadapter/test/regression/TestMain.java | 114 ++++++++++-------- .../jniadapter/test/template/TestMain.java | 9 +- .../jniadapter/test/utils/TestCallbacks.java | 21 ++++ 6 files changed, 112 insertions(+), 65 deletions(-) create mode 100644 test/java/foundation/pEp/jniadapter/test/utils/TestCallbacks.java diff --git a/test/java/foundation/pEp/jniadapter/test/basic/TestMain.java b/test/java/foundation/pEp/jniadapter/test/basic/TestMain.java index df44d03..1926ca9 100644 --- a/test/java/foundation/pEp/jniadapter/test/basic/TestMain.java +++ b/test/java/foundation/pEp/jniadapter/test/basic/TestMain.java @@ -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/TestContext.java b/test/java/foundation/pEp/jniadapter/test/framework/TestContext.java index 6ae9775..63a9e37 100644 --- a/test/java/foundation/pEp/jniadapter/test/framework/TestContext.java +++ b/test/java/foundation/pEp/jniadapter/test/framework/TestContext.java @@ -9,21 +9,30 @@ import java.util.Vector; public class TestContext { public Sync.DefaultCallback cb = new Sync.DefaultCallback(); - public Identity alice = new Identity(); - public Identity bob = new Identity(); + public Identity alice; + public Identity bob; public Message msgToSelf; public Message msgToBob; - public Vector vID = new Vector(); - public Vector vStr = new Vector(); + 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 = new Engine(); + public Engine engine; - public TestContext() throws Exception { + public TestContext() { } + + 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"; diff --git a/test/java/foundation/pEp/jniadapter/test/framework/TestUnit.java b/test/java/foundation/pEp/jniadapter/test/framework/TestUnit.java index 883707d..607ff51 100644 --- a/test/java/foundation/pEp/jniadapter/test/framework/TestUnit.java +++ b/test/java/foundation/pEp/jniadapter/test/framework/TestUnit.java @@ -3,12 +3,12 @@ import foundation.pEp.jniadapter.test.utils.TestUtils; import java.util.function.Consumer; -public class TestUnit { +public class TestUnit implements Runnable { String testUnitName = "default test unit"; - TestContext ctx; - Consumer lambda; + T ctx; + Consumer lambda; - public TestUnit(String name, TestContext c, Consumer consumer) throws Exception { + public TestUnit(String name, T c, Consumer consumer) { testUnitName = name; lambda = consumer; ctx = c; @@ -17,6 +17,7 @@ public class TestUnit { public void run() { TestUtils.logH1(testUnitName); try { + ctx.init(); lambda.accept(ctx); } catch (Throwable e) { TestUtils.logH1("TestUnit FAILED: " + e.toString()); diff --git a/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java b/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java index 50323f0..d9ec2cd 100644 --- a/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java +++ b/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java @@ -2,62 +2,72 @@ package foundation.pEp.jniadapter.test.regression; import foundation.pEp.jniadapter.test.framework.*; import foundation.pEp.jniadapter.*; +class RegTestContext extends TestContext { + // enhance the context + + @Override + public void init() throws Exception { + super.init(); + // init the enhancements + } +} + class TestMain { public static void main(String[] args) throws Exception { - new TestUnit("Engine.myself", new TestContext(), ctx -> { + new TestUnit("Engine.myself", new RegTestContext(), ctx -> { ctx.alice = ctx.engine.myself(ctx.alice); }).run(); - new TestUnit("Engine.encrypt_message", new TestContext(), ctx -> { + 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", new TestContext(), ctx -> { + 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", new TestContext(), ctx -> { + 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", new TestContext(), ctx -> { + 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", new TestContext(), ctx -> { +// 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", new TestContext(), ctx -> { + new TestUnit("Engine.outgoing_message_rating", new RegTestContext(), ctx -> { ctx.engine.outgoing_message_rating(ctx.msgToBob); }).run(); - new TestUnit("Engine.outgoing_message_rating_preview", new TestContext(), ctx -> { + new TestUnit("Engine.outgoing_message_rating_preview", new RegTestContext(), ctx -> { ctx.engine.outgoing_message_rating_preview(ctx.msgToBob); }).run(); - new TestUnit("Engine.get_identity", new TestContext(), ctx -> { + 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", new TestContext(), ctx -> { + 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", new TestContext(), ctx -> { + new TestUnit("Engine.blacklist_retrieve", new RegTestContext(), ctx -> { ctx.engine.blacklist_retrieve(); }).run(); //FAIL - new TestUnit("Engine.own_message_private_key_details", new TestContext(), ctx -> { + 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); @@ -65,63 +75,63 @@ class TestMain { ctx.engine.own_message_private_key_details(ctx.msgToBob); }).run(); - new TestUnit("Engine.OpenPGP_list_keyinfo", new TestContext(), ctx -> { + new TestUnit("Engine.OpenPGP_list_keyinfo", new RegTestContext(), ctx -> { ctx.engine.OpenPGP_list_keyinfo(""); }).run(); - new TestUnit("Engine.set_identity_flags", new TestContext(), ctx -> { + new TestUnit("Engine.set_identity_flags", new RegTestContext(), ctx -> { ctx.engine.set_identity_flags(ctx.alice, 0); }).run(); - new TestUnit("Engine.unset_identity_flags", new TestContext(), ctx -> { + new TestUnit("Engine.unset_identity_flags", new RegTestContext(), ctx -> { ctx.engine.unset_identity_flags(ctx.alice, 0); }).run(); - new TestUnit("Engine.own_identities_retrieve", new TestContext(), ctx -> { + new TestUnit("Engine.own_identities_retrieve", new RegTestContext(), ctx -> { ctx.engine.own_identities_retrieve(); }).run(); - new TestUnit("Engine.get_trustwords", new TestContext(), ctx -> { + 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", new TestContext(), ctx -> { + new TestUnit("Engine.get_trustwords_for_fprs", new RegTestContext(), ctx -> { ctx.alice = ctx.engine.myself(ctx.alice); ctx.bob = ctx.engine.myself(ctx.bob); ctx.engine.get_trustwords_for_fprs(ctx.alice.fpr, ctx.bob.fpr, "en", false); }).run(); - new TestUnit("Engine.get_message_trustwords", new TestContext(), ctx -> { + 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", new TestContext(), ctx -> { + new TestUnit("Engine.get_languagelist", new RegTestContext(), ctx -> { ctx.engine.get_languagelist(); }).run(); - new TestUnit("Engine.key_reset_trust", new TestContext(), ctx -> { + 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", new TestContext(), ctx -> { + 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", new TestContext(), ctx -> { + 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", new TestContext(), ctx -> { + new TestUnit("Engine.key_reset_all_own_keys", new RegTestContext(), ctx -> { ctx.engine.key_reset_all_own_keys(); }).run(); - new TestUnit("Engine.deliverHandshakeResult", new TestContext(), ctx -> { + new TestUnit("Engine.deliverHandshakeResult", new RegTestContext(), ctx -> { ctx.engine.deliverHandshakeResult(SyncHandshakeResult.SyncHandshakeCancel, ctx.vID); }).run(); @@ -132,119 +142,119 @@ class TestMain { //[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 TestContext(), ctx -> { +// 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 TestContext(), ctx -> { + 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", new TestContext(), ctx -> { + 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", new TestContext(), ctx -> { +// new TestUnit("Engine.config_cipher_suite", new RegTestContext(), ctx -> { // ctx.engine.config_cipher_suite(CipherSuite.pEpCipherSuiteDefault); // }).run(); - new TestUnit("Engine.trustwords", new TestContext(), ctx -> { + new TestUnit("Engine.trustwords", new RegTestContext(), ctx -> { ctx.engine.trustwords(ctx.alice); }).run(); - new TestUnit("Engine.updateIdentity", new TestContext(), ctx -> { + new TestUnit("Engine.updateIdentity", new RegTestContext(), ctx -> { ctx.engine.updateIdentity(ctx.alice); }).run(); - new TestUnit("Engine.setOwnKey", new TestContext(), ctx -> { + 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", new TestContext(), ctx -> { + new TestUnit("Engine.keyMistrusted", new RegTestContext(), ctx -> { ctx.alice = ctx.engine.myself(ctx.alice); ctx.engine.keyMistrusted(ctx.alice); }).run(); - new TestUnit("Engine.keyResetTrust", new TestContext(), ctx -> { + new TestUnit("Engine.keyResetTrust", new RegTestContext(), ctx -> { ctx.engine.keyResetTrust(ctx.alice); }).run(); - new TestUnit("Engine.trustPersonalKey", new TestContext(), ctx -> { + new TestUnit("Engine.trustPersonalKey", new RegTestContext(), ctx -> { ctx.engine.trustPersonalKey(ctx.alice); }).run(); - new TestUnit("Engine.trustOwnKey", new TestContext(), ctx -> { + new TestUnit("Engine.trustOwnKey", new RegTestContext(), ctx -> { ctx.alice = ctx.engine.myself(ctx.alice); ctx.engine.trustOwnKey(ctx.alice); }).run(); - new TestUnit("Engine.importKey", new TestContext(), ctx -> { + new TestUnit("Engine.importKey", new RegTestContext(), ctx -> { ctx.engine.importKey(ctx.key); }).run(); - new TestUnit("Engine.blacklist_add", new TestContext(), ctx -> { + new TestUnit("Engine.blacklist_add", new RegTestContext(), ctx -> { ctx.engine.blacklist_add("43"); }).run(); - new TestUnit("Engine.blacklist_delete", new TestContext(), ctx -> { + new TestUnit("Engine.blacklist_delete", new RegTestContext(), ctx -> { ctx.engine.blacklist_delete("43"); }).run(); - new TestUnit("Engine.blacklist_is_listed", new TestContext(), ctx -> { + new TestUnit("Engine.blacklist_is_listed", new RegTestContext(), ctx -> { ctx.engine.blacklist_is_listed("43"); }).run(); - new TestUnit("Engine.config_passive_mode", new TestContext(), ctx -> { + new TestUnit("Engine.config_passive_mode", new RegTestContext(), ctx -> { ctx.engine.config_passive_mode(false); }).run(); - new TestUnit("Engine.config_unencrypted_subject", new TestContext(), ctx -> { + new TestUnit("Engine.config_unencrypted_subject", new RegTestContext(), ctx -> { ctx.engine.config_unencrypted_subject(false); }).run(); - new TestUnit("Engine.getCrashdumpLog", new TestContext(), ctx -> { + new TestUnit("Engine.getCrashdumpLog", new RegTestContext(), ctx -> { ctx.engine.getCrashdumpLog(0); }).run(); - new TestUnit("Engine.getUserDirectory", new TestContext(), ctx -> { + new TestUnit("Engine.getUserDirectory", new RegTestContext(), ctx -> { ctx.engine.getUserDirectory(); }).run(); - new TestUnit("Engine.getMachineDirectory", new TestContext(), ctx -> { + new TestUnit("Engine.getMachineDirectory", new RegTestContext(), ctx -> { ctx.engine.getMachineDirectory(); }).run(); // AbstractEngine.java - new TestUnit("Engine.close", new TestContext(), ctx -> { + new TestUnit("Engine.close", new RegTestContext(), ctx -> { ctx.engine.close(); }).run(); - new TestUnit("Engine.getVersion", new TestContext(), ctx -> { + new TestUnit("Engine.getVersion", new RegTestContext(), ctx -> { ctx.engine.getVersion(); }).run(); - new TestUnit("Engine.getProtocolVersion", new TestContext(), ctx -> { + new TestUnit("Engine.getProtocolVersion", new RegTestContext(), ctx -> { ctx.engine.getProtocolVersion(); }).run(); - new TestUnit("Engine.startKeyserverLookup", new TestContext(), ctx -> { + new TestUnit("Engine.startKeyserverLookup", new RegTestContext(), ctx -> { ctx.engine.startKeyserverLookup(); }).run(); - new TestUnit("Engine.startSync", new TestContext(), ctx -> { + new TestUnit("Engine.startSync", new RegTestContext(), ctx -> { ctx.engine.startSync(); }).run(); - new TestUnit("Engine.stopSync", new TestContext(), ctx -> { + new TestUnit("Engine.stopSync", new RegTestContext(), ctx -> { ctx.engine.stopSync(); }).run(); - new TestUnit("Engine.isSyncRunning", new TestContext(), ctx -> { + new TestUnit("Engine.isSyncRunning", new RegTestContext(), ctx -> { ctx.engine.isSyncRunning(); }).run(); } diff --git a/test/java/foundation/pEp/jniadapter/test/template/TestMain.java b/test/java/foundation/pEp/jniadapter/test/template/TestMain.java index d0e4fe1..e3b9348 100644 --- a/test/java/foundation/pEp/jniadapter/test/template/TestMain.java +++ b/test/java/foundation/pEp/jniadapter/test/template/TestMain.java @@ -5,8 +5,15 @@ import foundation.pEp.jniadapter.*; class TestMain { public static void main(String[] args) throws Exception { - new TestUnit("Engine.myself",new TestContext() , ctx -> { + new TestUnit("Test Template",new TestContext() , 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/TestCallbacks.java b/test/java/foundation/pEp/jniadapter/test/utils/TestCallbacks.java new file mode 100644 index 0000000..96bd7da --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/utils/TestCallbacks.java @@ -0,0 +1,21 @@ +package foundation.pEp.jniadapter.test.utils; +import foundation.pEp.jniadapter.*; + +public class TestCallbacks implements Sync.MessageToSendCallback, Sync.NotifyHandshakeCallback { + public void messageToSend(Message message) { + TestUtils.logH1("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()); + } + + public void notifyHandshake(Identity myself, Identity partner, SyncHandshakeSignal signal) { + TestUtils.logH1("Notify handshake called"); + TestUtils.log("myself: " + TestUtils.identityToString(myself, false)); + TestUtils.log("Partner: " + TestUtils.identityToString(partner, false)); + TestUtils.log("Signal: " + signal); + } +} + + From f09fcbcaff9f195c98335dfa5b02003ed2057de7 Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 14 May 2020 23:51:58 +0200 Subject: [PATCH 10/12] more TestFramework (reduce dependencies) --- .../pEp/jniadapter/test/Makefile.conf | 6 + .../pEp/jniadapter/test/basic/Makefile | 4 +- .../pEp/jniadapter/test/basic/TestMain.java | 2 +- .../test/framework/AbstractTestContext.java | 5 + .../test/framework/TestContext.java | 53 --------- .../jniadapter/test/framework/TestLogger.java | 53 +++++++++ .../jniadapter/test/framework/TestUnit.java | 25 +++-- .../jniadapter/test/framework/TestUtils.java | 12 ++ .../test/framework/examples/Makefile.conf | 10 ++ .../framework/examples/helloworld/Makefile | 25 +++++ .../examples/helloworld/TestMain.java | 23 ++++ .../pEp/jniadapter/test/jni100/Makefile | 35 ++++++ .../pEp/jniadapter/test/jni100/TestMain.java | 27 +++++ .../pEp/jniadapter/test/jni88/Makefile | 3 +- .../pEp/jniadapter/test/jni91/Makefile | 3 +- .../pEp/jniadapter/test/jni92/Makefile | 5 +- .../pEp/jniadapter/test/jni92/TestMain.java | 25 +++-- .../pEp/jniadapter/test/jni94/Makefile | 3 +- .../pEp/jniadapter/test/jni94/TestMain.java | 31 ++---- .../pEp/jniadapter/test/regression/Makefile | 4 +- .../jniadapter/test/regression/TestMain.java | 3 +- .../pEp/jniadapter/test/template/Makefile | 7 +- .../jniadapter/test/template/TestMain.java | 4 +- .../test/utils/AdapterBaseTestContext.java | 105 ++++++++++++++++++ .../{TestUtils.java => AdapterTestUtils.java} | 54 +-------- .../jniadapter/test/utils/TestCallbacks.java | 19 ++-- 26 files changed, 371 insertions(+), 175 deletions(-) create mode 100644 test/java/foundation/pEp/jniadapter/test/framework/AbstractTestContext.java delete mode 100644 test/java/foundation/pEp/jniadapter/test/framework/TestContext.java create mode 100644 test/java/foundation/pEp/jniadapter/test/framework/TestLogger.java create mode 100644 test/java/foundation/pEp/jniadapter/test/framework/TestUtils.java create mode 100644 test/java/foundation/pEp/jniadapter/test/framework/examples/Makefile.conf create mode 100644 test/java/foundation/pEp/jniadapter/test/framework/examples/helloworld/Makefile create mode 100644 test/java/foundation/pEp/jniadapter/test/framework/examples/helloworld/TestMain.java create mode 100644 test/java/foundation/pEp/jniadapter/test/jni100/Makefile create mode 100644 test/java/foundation/pEp/jniadapter/test/jni100/TestMain.java create mode 100644 test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java rename test/java/foundation/pEp/jniadapter/test/utils/{TestUtils.java => AdapterTestUtils.java} (80%) diff --git a/test/java/foundation/pEp/jniadapter/test/Makefile.conf b/test/java/foundation/pEp/jniadapter/test/Makefile.conf index 0504c6a..c275826 100644 --- a/test/java/foundation/pEp/jniadapter/test/Makefile.conf +++ b/test/java/foundation/pEp/jniadapter/test/Makefile.conf @@ -9,6 +9,12 @@ 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 4d557f0..1383458 100644 --- a/test/java/foundation/pEp/jniadapter/test/basic/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/basic/Makefile @@ -5,8 +5,8 @@ TEST_UNIT_NAME=basic JAVA_CLASSES = \ SyncCallbacks.class \ - TestMain.class \ - ../utils/TestUtils.class + TestMain.class + .PHONY: compile run test clean diff --git a/test/java/foundation/pEp/jniadapter/test/basic/TestMain.java b/test/java/foundation/pEp/jniadapter/test/basic/TestMain.java index 1926ca9..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; 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/TestContext.java b/test/java/foundation/pEp/jniadapter/test/framework/TestContext.java deleted file mode 100644 index 63a9e37..0000000 --- a/test/java/foundation/pEp/jniadapter/test/framework/TestContext.java +++ /dev/null @@ -1,53 +0,0 @@ -package foundation.pEp.jniadapter.test.framework; -import foundation.pEp.jniadapter.test.utils.TestUtils; -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 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 TestContext() { } - - 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 = TestUtils.makeNewTestMessage(alice, alice, Message.Direction.Outgoing); - msgToBob = TestUtils.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) { - TestUtils.log("Could not open key file:" + fileName); - throw e; - } - } -} \ 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 index 607ff51..4df9ba2 100644 --- a/test/java/foundation/pEp/jniadapter/test/framework/TestUnit.java +++ b/test/java/foundation/pEp/jniadapter/test/framework/TestUnit.java @@ -1,29 +1,32 @@ package foundation.pEp.jniadapter.test.framework; -import foundation.pEp.jniadapter.test.utils.TestUtils; import java.util.function.Consumer; -public class TestUnit implements Runnable { +public class TestUnit implements Runnable { String testUnitName = "default test unit"; T ctx; Consumer lambda; - public TestUnit(String name, T c, Consumer consumer) { - testUnitName = name; - lambda = consumer; - ctx = c; + public TestUnit(String name, T context, Consumer lambda) { + this.testUnitName = name; + this.lambda = lambda; + this.ctx = context; } public void run() { - TestUtils.logH1(testUnitName); + TestLogger.logH1(testUnitName); + try { + //Init the Context ctx.init(); + //Run the test against the context lambda.accept(ctx); - } catch (Throwable e) { - TestUtils.logH1("TestUnit FAILED: " + e.toString()); + } catch (Throwable t) { + //Test fails, upon cought exception, otherwise succeeds + TestLogger.logH1("TestUnit FAILED: " + t.toString()); return; } - TestUtils.logH2("SUCCESS!"); + + 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/jni88/Makefile b/test/java/foundation/pEp/jniadapter/test/jni88/Makefile index 407b9f5..e8aa7aa 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni88/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/jni88/Makefile @@ -4,8 +4,7 @@ include ../Makefile.conf TEST_UNIT_NAME=jni88 JAVA_CLASSES = \ - TestMain.class \ - ../utils/TestUtils.class + TestMain.class .PHONY: compile run test clean diff --git a/test/java/foundation/pEp/jniadapter/test/jni91/Makefile b/test/java/foundation/pEp/jniadapter/test/jni91/Makefile index 0035de8..71fb5b6 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni91/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/jni91/Makefile @@ -4,8 +4,7 @@ include ../Makefile.conf TEST_UNIT_NAME=jni91 JAVA_CLASSES = \ - TestMain.class \ - ../utils/TestUtils.class + TestMain.class .PHONY: compile run test clean diff --git a/test/java/foundation/pEp/jniadapter/test/jni92/Makefile b/test/java/foundation/pEp/jniadapter/test/jni92/Makefile index fac4197..b1a5f4a 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni92/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/jni92/Makefile @@ -4,9 +4,10 @@ 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 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 d4cc4b4..5c221d6 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni94/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/jni94/Makefile @@ -5,7 +5,8 @@ TEST_UNIT_NAME=jni94 JAVA_CLASSES = \ TestMain.class \ - ../utils/TestUtils.class + +JAVA_CLASSES += $(JAVA_CLASSES_FRAMEWORK) .PHONY: compile run test clean 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/regression/Makefile b/test/java/foundation/pEp/jniadapter/test/regression/Makefile index e02cf3a..b92525c 100644 --- a/test/java/foundation/pEp/jniadapter/test/regression/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/regression/Makefile @@ -5,7 +5,9 @@ TEST_UNIT_NAME=regression JAVA_CLASSES = \ TestMain.class \ - ../utils/TestUtils.class + ../utils/AdapterBaseTestContext.class + +JAVA_CLASSES += $(JAVA_CLASSES_FRAMEWORK) .PHONY: compile run test clean diff --git a/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java b/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java index d9ec2cd..5133bd7 100644 --- a/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java +++ b/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java @@ -1,8 +1,9 @@ package foundation.pEp.jniadapter.test.regression; import foundation.pEp.jniadapter.test.framework.*; +import foundation.pEp.jniadapter.test.utils.*; import foundation.pEp.jniadapter.*; -class RegTestContext extends TestContext { +class RegTestContext extends AdapterBaseTestContext { // enhance the context @Override diff --git a/test/java/foundation/pEp/jniadapter/test/template/Makefile b/test/java/foundation/pEp/jniadapter/test/template/Makefile index 5b3ad94..81b12b9 100644 --- a/test/java/foundation/pEp/jniadapter/test/template/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/template/Makefile @@ -4,10 +4,9 @@ include ../Makefile.conf TEST_UNIT_NAME=template JAVA_CLASSES = \ - TestMain.class \ - ../framework/TestUnit.class \ - ../framework/TestContext.class \ - ../utils/TestUtils.class + TestMain.class + +JAVA_CLASSES += $(JAVA_CLASSES_FRAMEWORK) .PHONY: compile run test clean diff --git a/test/java/foundation/pEp/jniadapter/test/template/TestMain.java b/test/java/foundation/pEp/jniadapter/test/template/TestMain.java index e3b9348..79a29a8 100644 --- a/test/java/foundation/pEp/jniadapter/test/template/TestMain.java +++ b/test/java/foundation/pEp/jniadapter/test/template/TestMain.java @@ -1,11 +1,11 @@ package foundation.pEp.jniadapter.test.template; import foundation.pEp.jniadapter.test.framework.*; -import foundation.pEp.jniadapter.*; +import foundation.pEp.jniadapter.test.utils.AdapterBaseTestContext; class TestMain { public static void main(String[] args) throws Exception { - new TestUnit("Test Template",new TestContext() , ctx -> { + new TestUnit("Test Template",new AdapterBaseTestContext() , ctx -> { // do stuff using the context // Test FAILS on unhandled exception, otherwise SUCCESS 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 80% rename from test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java rename to test/java/foundation/pEp/jniadapter/test/utils/AdapterTestUtils.java index 332914c..2445599 100644 --- a/test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java +++ b/test/java/foundation/pEp/jniadapter/test/utils/AdapterTestUtils.java @@ -4,17 +4,7 @@ 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) { @@ -215,46 +205,4 @@ public class TestUtils { msg.setLongmsg("Hi i am the message longmsg"); return msg; } - - // ------------------------ 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 void logSectEnd(String msg) { - log(msg + "\n"); - } } \ 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 index 96bd7da..15ab223 100644 --- a/test/java/foundation/pEp/jniadapter/test/utils/TestCallbacks.java +++ b/test/java/foundation/pEp/jniadapter/test/utils/TestCallbacks.java @@ -1,20 +1,21 @@ 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) { - TestUtils.logH1("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()); + 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) { - TestUtils.logH1("Notify handshake called"); - TestUtils.log("myself: " + TestUtils.identityToString(myself, false)); - TestUtils.log("Partner: " + TestUtils.identityToString(partner, false)); - TestUtils.log("Signal: " + signal); + TestLogger.logH1("Notify handshake called"); + TestLogger.log("myself: " + AdapterTestUtils.identityToString(myself, false)); + TestLogger.log("Partner: " + AdapterTestUtils.identityToString(partner, false)); + TestLogger.log("Signal: " + signal); } } From 20cdbbf90bd142646d51e98859e19634c67366b9 Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 19 May 2020 23:54:39 +0200 Subject: [PATCH 12/12] Added templateAlice, templateAliceBob (from template) --- .../pEp/jniadapter/test/Makefile.conf | 2 +- .../jniadapter/test/jni92/SyncCallbacks.java | 24 -------------- .../test/{template => templateAlice}/Makefile | 2 +- .../{template => templateAlice}/TestMain.java | 4 +-- .../jniadapter/test/templateAliceBob/Makefile | 33 +++++++++++++++++++ .../test/templateAliceBob/TestMain.java | 21 ++++++++++++ .../{pep-home => per-user-dirs}/.dontdeleteme | 0 7 files changed, 58 insertions(+), 28 deletions(-) delete mode 100644 test/java/foundation/pEp/jniadapter/test/jni92/SyncCallbacks.java rename test/java/foundation/pEp/jniadapter/test/{template => templateAlice}/Makefile (91%) rename test/java/foundation/pEp/jniadapter/test/{template => templateAlice}/TestMain.java (83%) create mode 100644 test/java/foundation/pEp/jniadapter/test/templateAliceBob/Makefile create mode 100644 test/java/foundation/pEp/jniadapter/test/templateAliceBob/TestMain.java rename test/resources/{pep-home => per-user-dirs}/.dontdeleteme (100%) diff --git a/test/java/foundation/pEp/jniadapter/test/Makefile.conf b/test/java/foundation/pEp/jniadapter/test/Makefile.conf index c275826..bddc9d6 100644 --- a/test/java/foundation/pEp/jniadapter/test/Makefile.conf +++ b/test/java/foundation/pEp/jniadapter/test/Makefile.conf @@ -3,7 +3,7 @@ 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 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/template/Makefile b/test/java/foundation/pEp/jniadapter/test/templateAlice/Makefile similarity index 91% rename from test/java/foundation/pEp/jniadapter/test/template/Makefile rename to test/java/foundation/pEp/jniadapter/test/templateAlice/Makefile index 81b12b9..c02d07f 100644 --- a/test/java/foundation/pEp/jniadapter/test/template/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/templateAlice/Makefile @@ -1,7 +1,7 @@ include ../../../../../../../Makefile.conf include ../Makefile.conf -TEST_UNIT_NAME=template +TEST_UNIT_NAME=templateAlice JAVA_CLASSES = \ TestMain.class diff --git a/test/java/foundation/pEp/jniadapter/test/template/TestMain.java b/test/java/foundation/pEp/jniadapter/test/templateAlice/TestMain.java similarity index 83% rename from test/java/foundation/pEp/jniadapter/test/template/TestMain.java rename to test/java/foundation/pEp/jniadapter/test/templateAlice/TestMain.java index 79a29a8..0a8a847 100644 --- a/test/java/foundation/pEp/jniadapter/test/template/TestMain.java +++ b/test/java/foundation/pEp/jniadapter/test/templateAlice/TestMain.java @@ -1,5 +1,5 @@ -package foundation.pEp.jniadapter.test.template; -import foundation.pEp.jniadapter.test.framework.*; +package foundation.pEp.jniadapter.test.templateAlice; +import foundation.pEp.jniadapter.test.framework.*; import foundation.pEp.jniadapter.test.utils.AdapterBaseTestContext; 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/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