use of il.ac.bgu.cs.bp.bpjs.model.BProgram in project BPjs by bThink-BGU.
the class EngineExceptionTest method testInvalidBSyncCall.
@Test
public void testInvalidBSyncCall() throws InterruptedException {
BProgram sut = new BProgram("bad") {
@Override
protected void setupProgramScope(Scriptable scope) {
evaluate("var i=0;\n var j=42;\n var k=5; bsync({request:bp.Event(\"A\")});", "hardcoded");
}
};
try {
new BProgramRunner(sut).run();
fail("System should have thrown an error due to bsync called outside of a BThread.");
} catch (BPjsCodeEvaluationException exp) {
assertEquals(3, exp.getLineNumber());
assertEquals("hardcoded", exp.getSourceName());
assertTrue(exp.getMessage().contains("bsync"));
// make sure this is the friendly message
assertTrue(exp.getMessage().contains("Did you forget"));
assertEquals(1, exp.getScriptStackTrace().size());
}
}
use of il.ac.bgu.cs.bp.bpjs.model.BProgram in project BPjs by bThink-BGU.
the class EngineExceptionTest method testInvalidJavascript.
@Test
public void testInvalidJavascript() throws InterruptedException {
BProgram sut = new BProgram("bad") {
@Override
protected void setupProgramScope(Scriptable scope) {
evaluate("var j=9\n" + "#This isn't a javascript line.\n" + "var o=0;", "hardcoded");
}
};
try {
new BProgramRunner(sut).run();
fail("System should have thrown an error due to uncompilable Javascript code.");
} catch (BPjsCodeEvaluationException exp) {
assertEquals(2, exp.getLineNumber());
assertEquals(1, exp.getColumnNumber());
assertEquals("#This isn't a javascript line.", exp.getLineSource());
}
}
use of il.ac.bgu.cs.bp.bpjs.model.BProgram in project BPjs by bThink-BGU.
the class NoBSyncTest method test.
@Test
public void test() throws InterruptedException {
BProgram sut = new SingleResourceBProgram("noBSyncs.js", "noBSyncs");
new BProgramRunner(sut).run();
final Long actualValue = sut.getFromGlobalScope("shouldBe7", Long.class).get();
assertEquals(new Long(7), actualValue);
}
use of il.ac.bgu.cs.bp.bpjs.model.BProgram in project BPjs by bThink-BGU.
the class TTTButton method main.
public static void main(String[] args) throws InterruptedException {
// Create a program
BProgram bprog = new SingleResourceBProgram("BPJSTicTacToe.js");
bprog.setEventSelectionStrategy(new PrioritizedBSyncEventSelectionStrategy());
bprog.setDaemonMode(true);
JFrame f = new TicTacToeGameMain();
BProgramRunner rnr = new BProgramRunner(bprog);
rnr.addListener(new PrintBProgramRunnerListener());
TTTdisplayGame = new TTTDisplayGame(bprog, rnr);
rnr.run();
System.out.println("end of run");
}
use of il.ac.bgu.cs.bp.bpjs.model.BProgram in project BPjs by bThink-BGU.
the class ContinuationProgramStateTest method testEqualityFalse.
@Test
public void testEqualityFalse() throws Exception {
// Generate a continuation
BProgram bprog = new StringBProgram(SRC);
BProgramSyncSnapshot cur = bprog.setup();
cur = cur.start(exSvc);
final BThreadSyncSnapshot snapshot1 = cur.getBThreadSnapshots().iterator().next();
// Read frame data of P1
NativeContinuation nc1 = (NativeContinuation) snapshot1.getContinuation();
ContinuationProgramState sut1 = new ContinuationProgramState(nc1);
bprog = new StringBProgram(SRC_SHORT);
cur = bprog.setup();
cur = cur.start(exSvc);
final BThreadSyncSnapshot snapshot2 = cur.getBThreadSnapshots().iterator().next();
NativeContinuation nc2 = (NativeContinuation) snapshot2.getContinuation();
ContinuationProgramState sut2 = new ContinuationProgramState(nc2);
assertFalse(sut1.equals(sut2));
assertTrue(sut1.getProgramCounter() > sut2.getProgramCounter());
}
Aggregations