Browse Source

PityTest Framework improvements:

- copy constructor for TestUnit, so you can add the same TestUnit multiple times, with e.g. different context
- TestUnit.setContext() so you can add the same TestUnit multiple times, with e.g. different context
- TestUnit throws RuntimeException instead of Throwable
JNI-118
heck 5 years ago
parent
commit
7f2391ad60
  1. 2
      test/java/foundation/pEp/jniadapter/test/jni111/TestAlice.java
  2. 2
      test/java/foundation/pEp/jniadapter/test/jni115/TestAlice.java
  3. 31
      test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java
  4. 2
      test/java/foundation/pEp/pitytest/TestSuite.java
  5. 38
      test/java/foundation/pEp/pitytest/TestUnit.java

2
test/java/foundation/pEp/jniadapter/test/jni111/TestAlice.java

@ -16,7 +16,7 @@ import java.util.Vector;
class JNI111TestContext extends AdapterBaseTestContext { class JNI111TestContext extends AdapterBaseTestContext {
@Override @Override
public void init() throws Throwable { public void init() throws RuntimeException {
super.init(); super.init();
alice = null; alice = null;
bob = null; bob = null;

2
test/java/foundation/pEp/jniadapter/test/jni115/TestAlice.java

@ -19,7 +19,7 @@ class Jni115TestContext extends AdapterBaseTestContext {
public List<Message> messagesToBob; public List<Message> messagesToBob;
@Override @Override
public void init() throws Throwable { public void init() throws RuntimeException {
super.init(); super.init();
messagesToBobSmall = new ArrayList<>(); messagesToBobSmall = new ArrayList<>();
messagesToBobBig = new ArrayList<>(); messagesToBobBig = new ArrayList<>();

31
test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java

@ -63,7 +63,7 @@ public class AdapterBaseTestContext extends AbstractTestContext {
public Vector<Identity> vID; public Vector<Identity> vID;
public Vector<String> vStr; public Vector<String> vStr;
public void init() throws Throwable { public void init() throws RuntimeException {
vID = new Vector<Identity>(); vID = new Vector<Identity>();
vStr = new Vector<String>(); vStr = new Vector<String>();
@ -74,7 +74,7 @@ public class AdapterBaseTestContext extends AbstractTestContext {
TestLogger.logH2("Machine directory: "); TestLogger.logH2("Machine directory: ");
TestLogger.log(engine.getMachineDirectory()); TestLogger.log(engine.getMachineDirectory());
TestLogger.logH2("User directory:" ); TestLogger.logH2("User directory:");
TestLogger.log(engine.getUserDirectory()); TestLogger.log(engine.getUserDirectory());
@ -96,22 +96,27 @@ public class AdapterBaseTestContext extends AbstractTestContext {
Path path; Path path;
path = Paths.get(filenameBobPub); path = Paths.get(filenameBobPub);
keyBobPub = Files.readAllBytes(path); try {
keyBobPub = Files.readAllBytes(path);
path = Paths.get(filenameBobSec); path = Paths.get(filenameBobSec);
keyBobSec = Files.readAllBytes(path); keyBobSec = Files.readAllBytes(path);
path = Paths.get(filenameAlicePub); path = Paths.get(filenameAlicePub);
keyAlicePub = Files.readAllBytes(path); keyAlicePub = Files.readAllBytes(path);
path = Paths.get(filenameAliceSec); path = Paths.get(filenameAliceSec);
keyAliceSec = Files.readAllBytes(path); keyAliceSec = Files.readAllBytes(path);
path = Paths.get(filenameAlicePubPassphrase); path = Paths.get(filenameAlicePubPassphrase);
keyAlicePubPassphrase = Files.readAllBytes(path); keyAlicePubPassphrase = Files.readAllBytes(path);
path = Paths.get(filenameAliceSecPassphrase);
keyAliceSecPassphrase = Files.readAllBytes(path);
} catch (Throwable e) {
throw new RuntimeException(e);
}
path = Paths.get(filenameAliceSecPassphrase);
keyAliceSecPassphrase = Files.readAllBytes(path);
} }
} }

2
test/java/foundation/pEp/pitytest/TestSuite.java

@ -75,7 +75,7 @@ public class TestSuite {
} }
public void add(TestUnit t) { public void add(TestUnit t) {
tests.add(t); tests.add(t.copy());
} }
public void run() { public void run() {

38
test/java/foundation/pEp/pitytest/TestUnit.java

@ -44,20 +44,45 @@ public class TestUnit<T extends TestContextInterface> implements Runnable {
add(TestSuite.getDefault()); add(TestSuite.getDefault());
} }
//Shallow Copy
public TestUnit(TestUnit<T> orig) {
testUnitName = orig.testUnitName;
ctx = orig.ctx;
lambda = orig.lambda;
result = orig.result;
state = orig.state;
lastException = orig.lastException;
verboseMode = orig.verboseMode;
testColor = orig.testColor;
logFmtPadding = orig.logFmtPadding;
logFmtMsgLen = orig.logFmtMsgLen;
logFmtTestDuration = orig.logFmtTestDuration;
lineWidthMin = orig.lineWidthMin;
logFmtTestNameLen = orig.logFmtTestNameLen;
logFmtCtxNameLen = orig.logFmtCtxNameLen;
}
//Shallow Copy
public TestUnit<T> copy() {
return new TestUnit<>(this);
}
public boolean isVerboseMode() { public boolean isVerboseMode() {
return verboseMode; return verboseMode;
} }
public void setVerboseMode(boolean verboseMode) { public TestUnit<T> setVerboseMode(boolean verboseMode) {
this.verboseMode = verboseMode; this.verboseMode = verboseMode;
return this;
} }
public TermColor getTestColor() { public TermColor getTestColor() {
return testColor; return testColor;
} }
public void setTestColor(TermColor testColor) { public TestUnit<T> setTestColor(TermColor testColor) {
this.testColor = testColor; this.testColor = testColor;
return this;
} }
public TestState getResult() { public TestState getResult() {
@ -82,6 +107,11 @@ public class TestUnit<T extends TestContextInterface> implements Runnable {
return ctx; return ctx;
} }
public TestUnit<T> setContext(T ctx) {
this.ctx = ctx;
return this;
}
public void run() { public void run() {
TestUtils.standardOutErrEnabled(verboseMode); TestUtils.standardOutErrEnabled(verboseMode);
if (ctx.isUninitializable()) { if (ctx.isUninitializable()) {
@ -154,7 +184,7 @@ public class TestUnit<T extends TestContextInterface> implements Runnable {
} }
private void setTestResult(TestState r) { private void setTestResult(TestState r) {
assert (r == TestState.SKIPPED || r == TestState.FAILED || r == TestState.SUCCESS || r == TestState.UNEVALUATED ): "PityTest Internal: illegal result value '" + r +"'"; assert (r == TestState.SKIPPED || r == TestState.FAILED || r == TestState.SUCCESS || r == TestState.UNEVALUATED) : "PityTest Internal: illegal result value '" + r + "'";
result = r; result = r;
TestUtils.standardOutErrEnabled(true); TestUtils.standardOutErrEnabled(true);
logH1(makeLogString()); logH1(makeLogString());
@ -193,7 +223,7 @@ public class TestUnit<T extends TestContextInterface> implements Runnable {
DecimalFormat f = new DecimalFormat("0.000"); DecimalFormat f = new DecimalFormat("0.000");
String durationFmtd = f.format(testDuration.toMillis() / 1000.0); String durationFmtd = f.format(testDuration.toMillis() / 1000.0);
strTestDuration = TestUtils.padOrClipString(" [" + durationFmtd + " sec] ", "=", logFmtTestDuration, TestUtils.Alignment.Right, ".. "); strTestDuration = TestUtils.padOrClipString(" [" + durationFmtd + " sec] ", "=", logFmtTestDuration, TestUtils.Alignment.Right, ".. ");
} else { } else {
strTestDuration = TestUtils.padOrClipString("", "=", logFmtTestDuration, TestUtils.Alignment.Right, ".. "); strTestDuration = TestUtils.padOrClipString("", "=", logFmtTestDuration, TestUtils.Alignment.Right, ".. ");
} }

Loading…
Cancel
Save