Beispiel #1
0
  public void testTwoEvaluations() throws Exception {
    IWorkbenchWindow window = openTestWindow();
    IEvaluationService service = (IEvaluationService) window.getService(IEvaluationService.class);
    assertNotNull(service);

    MyEval listener1 = new MyEval();
    MyEval listener2 = new MyEval();
    IContextActivation context1 = null;
    IEvaluationReference evalRef1 = null;
    IEvaluationReference evalRef2 = null;
    IContextService contextService = null;
    try {
      evalRef1 =
          service.addEvaluationListener(
              new ActiveContextExpression(CONTEXT_ID1, new String[] {ISources.ACTIVE_CONTEXT_NAME}),
              listener1,
              IEvaluationService.RESULT);
      assertEquals(1, listener1.count);
      assertFalse(listener1.currentValue);

      evalRef2 =
          service.addEvaluationListener(
              new ActiveContextExpression(CONTEXT_ID1, new String[] {ISources.ACTIVE_CONTEXT_NAME}),
              listener2,
              IEvaluationService.RESULT);
      assertEquals(1, listener2.count);
      assertFalse(listener2.currentValue);
      evalRef2.setResult(true);

      contextService = (IContextService) window.getService(IContextService.class);
      context1 = contextService.activateContext(CONTEXT_ID1);
      assertEquals(2, listener1.count);
      assertTrue(listener1.currentValue);
      // we already set this guy to true, he should skip
      assertEquals(1, listener2.count);
      assertFalse(listener2.currentValue);

      evalRef1.setResult(false);
      contextService.deactivateContext(context1);
      context1 = null;
      assertEquals(2, listener2.count);
      assertFalse(listener2.currentValue);

      // we already set this guy to false, so he should be the old
      // values
      assertEquals(2, listener1.count);
      assertTrue(listener1.currentValue);

    } finally {
      if (context1 != null) {
        contextService.deactivateContext(context1);
      }
      if (evalRef1 != null) {
        service.removeEvaluationListener(evalRef1);
      }
      if (evalRef2 != null) {
        service.removeEvaluationListener(evalRef2);
      }
    }
  }
Beispiel #2
0
  public void testBasicService() throws Exception {
    IWorkbenchWindow window = openTestWindow();
    IEvaluationService service = (IEvaluationService) window.getService(IEvaluationService.class);
    assertNotNull(service);

    MyEval listener = new MyEval();
    IContextActivation context1 = null;
    IEvaluationReference evalRef = null;
    IContextService contextService = null;
    try {
      evalRef =
          service.addEvaluationListener(
              new ActiveContextExpression(CONTEXT_ID1, new String[] {ISources.ACTIVE_CONTEXT_NAME}),
              listener,
              IEvaluationService.RESULT);
      assertEquals(1, listener.count);
      assertFalse(listener.currentValue);

      contextService = (IContextService) window.getService(IContextService.class);
      context1 = contextService.activateContext(CONTEXT_ID1);
      assertEquals(2, listener.count);
      assertTrue(listener.currentValue);

      contextService.deactivateContext(context1);
      context1 = null;
      assertEquals(3, listener.count);
      assertFalse(listener.currentValue);

      service.removeEvaluationListener(evalRef);
      evalRef = null;
      assertEquals(4, listener.count);

      context1 = contextService.activateContext(CONTEXT_ID1);
      assertEquals(4, listener.count);
      assertFalse(listener.currentValue);
      contextService.deactivateContext(context1);
      context1 = null;
      assertEquals(4, listener.count);
      assertFalse(listener.currentValue);
    } finally {
      if (context1 != null) {
        contextService.deactivateContext(context1);
      }
      if (evalRef != null) {
        service.removeEvaluationListener(evalRef);
      }
    }
  }