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;