From 784a49ce70664f8e33c3a0c1b8640de6870600f4 Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 25 Feb 2021 23:35:23 +0100 Subject: [PATCH] JNI-134 - Tests for class Message getter/setter --- .../pEp/jniadapter/test/jni129/Makefile | 37 ++++++ .../pEp/jniadapter/test/jni129/TestAlice.java | 109 ++++++++++++++++++ .../pEp/jniadapter/test/jni134/Makefile | 37 ++++++ .../pEp/jniadapter/test/jni134/TestAlice.java | 109 ++++++++++++++++++ 4 files changed, 292 insertions(+) create mode 100644 test/java/foundation/pEp/jniadapter/test/jni129/Makefile create mode 100644 test/java/foundation/pEp/jniadapter/test/jni129/TestAlice.java create mode 100644 test/java/foundation/pEp/jniadapter/test/jni134/Makefile create mode 100644 test/java/foundation/pEp/jniadapter/test/jni134/TestAlice.java diff --git a/test/java/foundation/pEp/jniadapter/test/jni129/Makefile b/test/java/foundation/pEp/jniadapter/test/jni129/Makefile new file mode 100644 index 0000000..51f27d0 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/jni129/Makefile @@ -0,0 +1,37 @@ +include ../../../../../../../Makefile.conf +include ../Makefile.conf + +TEST_UNIT_NAME=jni129 + +JAVA_CLASSES = \ + TestAlice.class \ + ../utils/AdapterBaseTestContext.class \ + ../utils/AdapterTestUtils.class \ + ../utils/TestCallbacks.class + +.PHONY: pitytest compile alice test clean + +all: alice compile + +pitytest: + $(MAKE) -C $(PITYTEST_DIR) + +alice: compile clean-pep-home-alice + cd $(JAVA_CWD);pwd;HOME=$(JAVA_PEP_HOME_DIR_ALICE) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestAlice + +compile: $(JAVA_CLASSES) pitytest + +%.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: clean-pep-home-alice + +clean-pep-home-alice: + rm -rf $(PEP_HOME_DIR_ALICE)/.pEp diff --git a/test/java/foundation/pEp/jniadapter/test/jni129/TestAlice.java b/test/java/foundation/pEp/jniadapter/test/jni129/TestAlice.java new file mode 100644 index 0000000..6dcced6 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/jni129/TestAlice.java @@ -0,0 +1,109 @@ +package foundation.pEp.jniadapter.test.jni129; + +import foundation.pEp.jniadapter.Blob; +import foundation.pEp.jniadapter.Identity; +import foundation.pEp.jniadapter.Message; +import foundation.pEp.jniadapter.test.utils.AdapterBaseTestContext; +import foundation.pEp.pitytest.TestSuite; +import foundation.pEp.pitytest.TestUnit; +import foundation.pEp.pitytest.utils.TestUtils; + +import java.util.Date; +import java.util.Vector; + +class Jni129TestContext extends AdapterBaseTestContext { + @Override + public AdapterBaseTestContext init() throws Throwable { + super.init(); + return this; + } +} + +class TestAlice { + public static void main(String[] args) throws Exception { + TestSuite.getDefault().setVerbose(true); + TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN); + + AdapterBaseTestContext jni129Ctx = new Jni129TestContext(); + + new TestUnit("setDir() == getDir() ", new Jni129TestContext(), ctx -> { + Message msg = new Message(); + Message.Direction inVal = ctx.msgDirOutgoing; + msg.setDir(inVal); + Message.Direction outVal = msg.getDir(); + assert outVal == inVal : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; + }); + + new TestUnit("setId() == getId() ", new Jni129TestContext(), ctx -> { + Message msg = new Message(); + String inVal = "23"; + msg.setId(inVal); + String outVal = msg.getId(); + assert outVal.equals(inVal) : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; + }); + + new TestUnit("setShortmsg() == getShortmsg() ", new Jni129TestContext(), ctx -> { + Message msg = new Message(); + String inVal = "23"; + msg.setShortmsg(inVal); + String outVal = msg.getShortmsg(); + assert outVal.equals(inVal) : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; + }); + + new TestUnit("setLongmsg() == getLongmsg() ", new Jni129TestContext(), ctx -> { + Message msg = new Message(); + String inVal = "23"; + msg.setLongmsg(inVal); + String outVal = msg.getLongmsg(); + assert outVal.equals(inVal) : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; + }); + + new TestUnit("setLongmsgFormatted() == getLongmsgFormatted() ", new Jni129TestContext(), ctx -> { + Message msg = new Message(); + String inVal = "23"; + msg.setLongmsgFormatted(inVal); + String outVal = msg.getLongmsgFormatted(); + assert outVal.equals(inVal) : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; + }); + + new TestUnit("setAttachments() == getAttachments() ", new Jni129TestContext(), ctx -> { + Message msg = new Message(); + Vector inVal = ctx.attachments; + msg.setAttachments(inVal); + Vector outVal = msg.getAttachments(); + for (int i = 0; i < 3; i++) { + Blob inElem = inVal.get(i); + Blob outElem = outVal.get(i); + assert inElem == inElem : "\nreturned '" + outElem + "' instead of '" + inElem + "'"; + } + }); + + new TestUnit("setSent() == getSent() ", new Jni129TestContext(), ctx -> { + Message msg = new Message(); + Date inVal = new Date(); + msg.setSent(inVal); + Date outVal = msg.getSent(); + assert outVal == inVal : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; + }); + + new TestUnit("setRecv() == getRecv() ", new Jni129TestContext(), ctx -> { + Message msg = new Message(); + Date inVal = new Date(); + msg.setRecv(inVal); + Date outVal = msg.getRecv(); + assert outVal == inVal : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; + }); + + new TestUnit("setFrom() == getFrom() ", new Jni129TestContext(), ctx -> { + Message msg = new Message(); + Identity inVal = ctx.alice; + msg.setFrom(inVal); + Identity outVal = msg.getFrom(); + assert outVal.equals(inVal) : "\nreturned '" + outVal + "'\nexpected '" + inVal + "'"; + }); + + TestSuite.getDefault().run(); + } +} + + diff --git a/test/java/foundation/pEp/jniadapter/test/jni134/Makefile b/test/java/foundation/pEp/jniadapter/test/jni134/Makefile new file mode 100644 index 0000000..5fa310c --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/jni134/Makefile @@ -0,0 +1,37 @@ +include ../../../../../../../Makefile.conf +include ../Makefile.conf + +TEST_UNIT_NAME=jni134 + +JAVA_CLASSES = \ + TestAlice.class \ + ../utils/AdapterBaseTestContext.class \ + ../utils/AdapterTestUtils.class \ + ../utils/TestCallbacks.class + +.PHONY: pitytest compile alice test clean + +all: alice compile + +pitytest: + $(MAKE) -C $(PITYTEST_DIR) + +alice: compile clean-pep-home-alice + cd $(JAVA_CWD);pwd;HOME=$(JAVA_PEP_HOME_DIR_ALICE) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestAlice + +compile: $(JAVA_CLASSES) pitytest + +%.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: clean-pep-home-alice + +clean-pep-home-alice: + rm -rf $(PEP_HOME_DIR_ALICE)/.pEp diff --git a/test/java/foundation/pEp/jniadapter/test/jni134/TestAlice.java b/test/java/foundation/pEp/jniadapter/test/jni134/TestAlice.java new file mode 100644 index 0000000..5de6710 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/jni134/TestAlice.java @@ -0,0 +1,109 @@ +package foundation.pEp.jniadapter.test.jni134; + +import foundation.pEp.jniadapter.Blob; +import foundation.pEp.jniadapter.Identity; +import foundation.pEp.jniadapter.Message; +import foundation.pEp.jniadapter.test.utils.AdapterBaseTestContext; +import foundation.pEp.pitytest.TestSuite; +import foundation.pEp.pitytest.TestUnit; +import foundation.pEp.pitytest.utils.TestUtils; + +import java.util.Date; +import java.util.Vector; + +class Jni134TestContext extends AdapterBaseTestContext { + @Override + public AdapterBaseTestContext init() throws Throwable { + super.init(); + return this; + } +} + +class TestAlice { + public static void main(String[] args) throws Exception { + TestSuite.getDefault().setVerbose(true); + TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN); + + AdapterBaseTestContext jni134Ctx = new Jni134TestContext(); + + new TestUnit("setDir() == getDir() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + Message.Direction inVal = ctx.msgDirOutgoing; + msg.setDir(inVal); + Message.Direction outVal = msg.getDir(); + assert outVal == inVal : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; + }); + + new TestUnit("setId() == getId() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + String inVal = "23"; + msg.setId(inVal); + String outVal = msg.getId(); + assert outVal.equals(inVal) : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; + }); + + new TestUnit("setShortmsg() == getShortmsg() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + String inVal = "23"; + msg.setShortmsg(inVal); + String outVal = msg.getShortmsg(); + assert outVal.equals(inVal) : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; + }); + + new TestUnit("setLongmsg() == getLongmsg() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + String inVal = "23"; + msg.setLongmsg(inVal); + String outVal = msg.getLongmsg(); + assert outVal.equals(inVal) : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; + }); + + new TestUnit("setLongmsgFormatted() == getLongmsgFormatted() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + String inVal = "23"; + msg.setLongmsgFormatted(inVal); + String outVal = msg.getLongmsgFormatted(); + assert outVal.equals(inVal) : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; + }); + + new TestUnit("setAttachments() == getAttachments() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + Vector inVal = ctx.attachments; + msg.setAttachments(inVal); + Vector outVal = msg.getAttachments(); + for (int i = 0; i < 3; i++) { + Blob inElem = inVal.get(i); + Blob outElem = outVal.get(i); + assert inElem == inElem : "\nreturned '" + outElem + "' instead of '" + inElem + "'"; + } + }); + + new TestUnit("setSent() == getSent() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + Date inVal = new Date(); + msg.setSent(inVal); + Date outVal = msg.getSent(); + assert outVal == inVal : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; + }); + + new TestUnit("setRecv() == getRecv() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + Date inVal = new Date(); + msg.setRecv(inVal); + Date outVal = msg.getRecv(); + assert outVal == inVal : "\nreturned '" + outVal + "' instead of '" + inVal + "'"; + }); + + new TestUnit("setFrom() == getFrom() ", new Jni134TestContext(), ctx -> { + Message msg = new Message(); + Identity inVal = ctx.alice; + msg.setFrom(inVal); + Identity outVal = msg.getFrom(); + assert outVal.equals(inVal) : "\nreturned '" + outVal + "'\nexpected '" + inVal + "'"; + }); + + TestSuite.getDefault().run(); + } +} + +