
26 changed files with 371 additions and 175 deletions
@ -0,0 +1,5 @@ |
|||||
|
package foundation.pEp.jniadapter.test.framework; |
||||
|
|
||||
|
public interface AbstractTestContext { |
||||
|
void init() throws Throwable; |
||||
|
} |
@ -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<Identity> vID; |
|
||||
public Vector<String> 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<Identity>(); |
|
||||
vStr = new Vector<String>(); |
|
||||
|
|
||||
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; |
|
||||
} |
|
||||
} |
|
||||
} |
|
@ -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"); |
||||
|
} |
||||
|
} |
@ -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"); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -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 |
@ -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) |
@ -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<HelloWorldTestContext>("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(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
@ -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 |
@ -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<AdapterBaseTestContext>("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(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
@ -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<Identity> vID; |
||||
|
public Vector<String> 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<Identity>(); |
||||
|
vStr = new Vector<String>(); |
||||
|
|
||||
|
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<Identity> vID; |
||||
|
public Vector<String> 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; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
*/ |
Loading…
Reference in new issue