コード例 #1
0
  public void test_unregister_1() throws PrologException, IOException {
    // Test invalid object_id unregistration
    theory = "demo(Obj1) :- unregister(Obj1).";
    engine.setTheory(new Theory(theory));
    info = engine.solve("demo(Res).");
    assertEquals(true, info.isHalted());

    setPath(true);
    theory =
        "demo(Obj) :- \n"
            + "set_classpath(["
            + paths
            + "]), \n"
            + "java_object('Counter', [], Obj), \n"
            + "Obj <- inc, \n"
            + "Obj <- inc, \n"
            + "register(Obj), unregister(Obj).";
    engine.setTheory(new Theory(theory));
    info = engine.solve("demo(Res).");
    assertEquals(true, info.isSuccess());
    OOLibrary lib = (OOLibrary) engine.getLibrary("alice.tuprolog.lib.OOLibrary");
    Struct id = (Struct) info.getTerm("Res");
    Object obj = lib.getRegisteredObject(id);
    assertNull(obj);
  }
コード例 #2
0
 public void testDynamicObjectsRetrival() throws PrologException {
   Prolog engine = new Prolog();
   OOLibrary lib = (OOLibrary) engine.getLibrary("alice.tuprolog.lib.OOLibrary");
   String theory =
       "demo(C) :- \n"
           + "java_object('alice.tuprolog.TestCounter', [], C), \n"
           + "C <- update, \n"
           + "C <- update. \n";
   engine.setTheory(new Theory(theory));
   SolveInfo info = engine.solve("demo(Obj).");
   Struct id = (Struct) info.getVarValue("Obj");
   TestCounter counter = (TestCounter) lib.getRegisteredDynamicObject(id);
   assertEquals(2, counter.getValue());
 }
コード例 #3
0
 public void testAnonymousObjectRegistration()
     throws InvalidTheoryException, InvalidObjectIdException {
   OOLibrary lib = (OOLibrary) engine.getLibrary("alice.tuprolog.lib.OOLibrary");
   String theory = "demo(X) :- X <- update. \n";
   engine.setTheory(new Theory(theory));
   TestCounter counter = new TestCounter();
   // check registering behaviour
   Struct t = lib.register(counter);
   engine.solve(new Struct("demo", t));
   assertEquals(1, counter.getValue());
   // check unregistering behaviour
   lib.unregister(t);
   SolveInfo goal = engine.solve(new Struct("demo", t));
   assertFalse(goal.isSuccess());
 }