Search in sources :

Example 16 with BProgram

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());
    }
}
Also used : BPjsCodeEvaluationException(il.ac.bgu.cs.bp.bpjs.exceptions.BPjsCodeEvaluationException) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) Scriptable(org.mozilla.javascript.Scriptable) Test(org.junit.Test)

Example 17 with BProgram

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());
    }
}
Also used : BPjsCodeEvaluationException(il.ac.bgu.cs.bp.bpjs.exceptions.BPjsCodeEvaluationException) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) Scriptable(org.mozilla.javascript.Scriptable) Test(org.junit.Test)

Example 18 with BProgram

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);
}
Also used : SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) Test(org.junit.Test)

Example 19 with BProgram

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");
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) JFrame(javax.swing.JFrame) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) PrioritizedBSyncEventSelectionStrategy(il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)

Example 20 with BProgram

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());
}
Also used : BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) NativeContinuation(org.mozilla.javascript.NativeContinuation) BProgramSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot) BThreadSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) Test(org.junit.Test)

Aggregations

BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)36 Test (org.junit.Test)29 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)23 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)21 BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)11 BProgramSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot)10 BThreadSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot)9 BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)8 PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)7 NativeContinuation (org.mozilla.javascript.NativeContinuation)7 BriefPrintDfsVerifierListener (il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener)5 Scriptable (org.mozilla.javascript.Scriptable)5 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)4 DfsBProgramVerifier (il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier)3 VerificationResult (il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult)3 BPjsCodeEvaluationException (il.ac.bgu.cs.bp.bpjs.exceptions.BPjsCodeEvaluationException)2 ExecutorServiceMaker (il.ac.bgu.cs.bp.bpjs.internal.ExecutorServiceMaker)2 EventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.EventSelectionStrategy)2 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)2 SimpleEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.SimpleEventSelectionStrategy)2