
6 changed files with 133 additions and 0 deletions
@ -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<Identity> vID = new Vector<Identity>(); |
||||
|
public Vector<String> vStr = new Vector<String>(); |
||||
|
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; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -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<TestContext> lambda; |
||||
|
|
||||
|
public TestUnit(String name, TestContext c, Consumer<TestContext> 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!"); |
||||
|
} |
||||
|
} |
||||
|
|
@ -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 |
@ -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(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
Loading…
Reference in new issue