예제 #1
0
  public void test_CollectionLiteralExp_checkElementType_emptySet() {
    CollectionLiteralExp cl = factory.createCollectionLiteralExp();
    cl.setKind(CollectionKind.SET_LITERAL);
    CollectionType ctype = factory.createSetType();
    ctype.setElementType(fruit);
    cl.setType(ctype);

    assertProblem(cl, ExpressionsValidator.COLLECTION_LITERAL_EXP__ELEMENT_TYPE);

    ctype.setElementType(getOCLStandardLibrary().getOclVoid());

    assertOK(cl, ExpressionsValidator.COLLECTION_LITERAL_EXP__ELEMENT_TYPE);
  }
예제 #2
0
  public void test_CollectionItem_checkItemType() {
    CollectionItem i = factory.createCollectionItem();
    CollectionType ctype = factory.createCollectionType();
    ctype.setElementType(fruit);
    i.setType(ctype);

    CollectionLiteralExp item = factory.createCollectionLiteralExp();
    CollectionType itemType = factory.createCollectionType();
    itemType.setElementType(apple);
    item.setType(itemType);

    i.setItem(item);

    assertProblem(i, ExpressionsValidator.COLLECTION_ITEM__ITEM_TYPE);

    item.setType(ctype);

    assertOK(i, ExpressionsValidator.COLLECTION_ITEM__ITEM_TYPE);
  }
예제 #3
0
  /** Tests the case of a null operation (that it doesn't throw an NPE). */
  public void test_OperationCallExp_checkArgumentCount_nullOperation_231515() {
    OperationCallExp o = factory.createOperationCallExp();

    o.setReferredOperation(null); // be explicit on the purpose of the test

    OCLExpression arg = factory.createUnspecifiedValueExp();
    o.getArgument().add(arg);
    CollectionType ctype = factory.createOrderedSetType();
    ctype.setElementType(color);
    arg.setType(ctype);

    assertOK(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENT_COUNT);

    o.getArgument().add(factory.createCollectionLiteralExp());

    assertOK(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENT_COUNT);

    o.getArgument().clear();

    assertOK(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENT_COUNT);
  }
예제 #4
0
  public void test_CollectionLiteralExp_checkElementType() {
    CollectionLiteralExp cl = factory.createCollectionLiteralExp();
    cl.setKind(CollectionKind.SET_LITERAL);
    CollectionType ctype = factory.createSetType();
    ctype.setElementType(fruit);
    cl.setType(ctype);

    CollectionItem item1 = factory.createCollectionItem();
    item1.setType(apple);
    CollectionItem item2 = factory.createCollectionItem();
    item2.setType(color);

    cl.getPart().add(item1);
    cl.getPart().add(item2);

    assertProblem(cl, ExpressionsValidator.COLLECTION_LITERAL_EXP__ELEMENT_TYPE);

    item2.setType(fruit);

    assertOK(cl, ExpressionsValidator.COLLECTION_LITERAL_EXP__ELEMENT_TYPE);
  }
예제 #5
0
  public void test_OperationCallExp_checkArgumentCount() {
    OperationCallExp o = factory.createOperationCallExp();

    EClass fruitUtil = (EClass) fruitPackage.getEClassifier("FruitUtil");
    EOperation oper = fruitUtil.getEOperations().get(0);
    o.setReferredOperation(oper);

    OCLExpression arg = factory.createUnspecifiedValueExp();
    o.getArgument().add(arg);
    CollectionType ctype = factory.createOrderedSetType();
    ctype.setElementType(color);
    arg.setType(ctype);

    assertOK(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENT_COUNT);

    o.getArgument().add(factory.createCollectionLiteralExp());

    assertProblem(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENT_COUNT);

    o.getArgument().clear();

    assertProblem(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENT_COUNT);
  }
예제 #6
0
  public void test_LoopExp_checkLoopVariableType() {
    LoopExp l = factory.createIterateExp();

    CollectionType ctype = factory.createCollectionType();
    ctype.setElementType(fruit);
    OCLExpression source = factory.createCollectionLiteralExp();
    source.setType(ctype);
    l.setSource(source);

    Variable iter = factory.createVariable();
    iter.setType(fruit);
    l.getIterator().add(iter);

    iter = factory.createVariable();
    iter.setType(apple);
    l.getIterator().add(iter);

    assertProblem(l, ExpressionsValidator.LOOP_EXP__LOOP_VARIABLE_TYPE);

    iter.setType(fruit);

    assertOK(l, ExpressionsValidator.LOOP_EXP__LOOP_VARIABLE_TYPE);
  }