Ejemplo n.º 1
0
  private void printGraph(EFG graph) {
    StringBuffer buff = new StringBuffer();

    List<EventType> eventList = graph.getEvents().getEvent();
    List<RowType> lRow = graph.getEventGraph().getRow();

    for (int row = 0; row < lRow.size(); row++) {
      List<Integer> rowVals = lRow.get(row).getE();

      for (int col = 0; col < rowVals.size(); col++) {

        int cell = rowVals.get(col);
        if (cell > 0) {
          EventType firstEvent = eventList.get((row));
          EventType secondEvent = eventList.get(col);

          buff.append(
              "\t"
                  + "\""
                  + firstEvent.getEventId()
                  + "\""
                  + "->"
                  + "\""
                  + secondEvent.getEventId()
                  + "\"");
          buff.append("\t/*" + cell + "*/");

          buff.append("\n");
        }
      }
    }

    System.out.println(buff);
  }
Ejemplo n.º 2
0
  /** Get initial events */
  private void parseInitialEvents() {

    initialEvents = new ArrayList<EventType>();

    if (inputGraph == null) return;

    List<EventType> eventList = inputGraph.getEvents().getEvent();
    for (EventType event : eventList) {
      if (event.isInitial() && preds.get(event) == null) {
        initialEvents.add(event);
      }
    }
  }
Ejemplo n.º 3
0
  /**
   * Get event list of interest. For example System interaction and Terminal events in EIG
   *
   * @return
   */
  List<EventType> getEventList() {

    List<EventType> lOutputEvents = new ArrayList<EventType>();

    if (this.inputGraph == null) return lOutputEvents;
    List<EventType> lInputEvents = inputGraph.getEvents().getEvent();

    for (EventType event : lInputEvents) {
      if (GUITARConstants.SYSTEM_INTERACTION.equals(event.getType())
          || GUITARConstants.TERMINAL.equals(event.getType())) lOutputEvents.add(event);
    }

    return lOutputEvents;
  }
Ejemplo n.º 4
0
  /** Get follow relations in the input graph */
  private void parseFollowRelations() {

    if (inputGraph == null) return;

    List<EventType> eventList = inputGraph.getEvents().getEvent();
    int eventGraphSize = eventList.size();
    EventGraphType eventGraph = inputGraph.getEventGraph();

    succs = new Hashtable<EventType, Vector<EventType>>();
    preds = new Hashtable<EventType, Vector<EventType>>();

    for (int row = 0; row < eventGraphSize; row++) {

      EventType currentEvent = eventList.get(row);
      // String currentEventType = currentEvent.getType();

      Vector<EventType> s = new Vector<EventType>();

      for (int col = 0; col < eventGraphSize; col++) {

        // EventType other = eventList.get(col);
        // String eventType = other .getType();

        int relation = eventGraph.getRow().get(row).getE().get(col);
        // int relation = eventGraph.getRow().get(col).getE().get(row);

        // Other is followed by current event: current -> other
        if (relation != GUITARConstants.NO_EDGE) {

          EventType otherEvent = eventList.get(col);
          s.add(otherEvent);

          if (relation == GUITARConstants.REACHING_EDGE
              && !otherEvent.getEventId().equals(currentEvent.getEventId())) {

            // Create preds list
            Vector<EventType> p = preds.get(otherEvent);
            if (p == null) {
              p = new Vector<EventType>();
            }
            p.add(currentEvent);
            preds.put(otherEvent, p);
          }
        }
        succs.put(currentEvent, s);
      }
    }
  }
Ejemplo n.º 5
0
  private void generateWithLength(int length, LinkedList<EventType> posfix, EventType root) {
    if (length <= 1) {
      LinkedList<EventType> path = getPathToRoot(root);
      if (path != null) {
        path.addAll(posfix);

        writeToFile(
            TestCaseGeneratorConfiguration.OUTPUT_DIR
                + File.separator
                + TEST_NAME_PREFIX
                + (index)
                + TEST_NAME_SUFIX,
            path);
        index++;

      } else {
        GUITARLog.log.info("root: " + root.getWidgetId());
        GUITARLog.log.info(posfix + " is unreachable");
      }

    } else {
      for (EventType succEvent : succs.get(root)) {
        LinkedList<EventType> extendedPosfix = new LinkedList<EventType>(posfix);
        extendedPosfix.addLast(root);
        generateWithLength(length - 1, extendedPosfix, succEvent);
      }
    }
  }
Ejemplo n.º 6
0
 /**
  * Find path to root
  *
  * @param event
  * @return
  */
 private LinkedList<EventType> pathToRoot(EventType event) {
   if (initialEvents.contains(event)) {
     LinkedList<EventType> path = new LinkedList<EventType>();
     path.add(event);
     return path;
   } else {
     Vector<EventType> predEventList = preds.get(event);
     if (predEventList == null) return null;
     else if (predEventList.size() == 0) {
       System.out.println(event.getEventId() + " has empty predEventList");
       return null;
     } else {
       for (EventType pred : predEventList) {
         // System.out.println("------------------------");
         // System.out.println("EventID: "+pred.getEventId());
         // System.out.println("PredID: "+pred.getEventId());
         //
         LinkedList<EventType> predPathToRoot = pathToRoot(pred);
         if (predPathToRoot == null) {
           continue;
         } else if (!predPathToRoot.contains(event)) {
           predPathToRoot.add(event);
           return predPathToRoot;
         }
       }
       return null;
     }
   }
 }
Ejemplo n.º 7
0
  private void printGraph() {
    // GUITARLog.log.info("Graph");

    List<EventType> eventList = efg.getEvents().getEvent();
    int eventGraphSize = eventList.size();
    EventGraphType eventGraph = efg.getEventGraph();

    for (int row = 0; row < eventGraphSize; row++) {

      EventType currentEvent = eventList.get(row);
      Vector<EventType> s = new Vector<EventType>();

      for (int col = 0; col < eventGraphSize; col++) {

        EventType event = eventList.get(col);

        int relation = eventGraph.getRow().get(row).getE().get(col);

        if (relation == GUITARConstants.FOLLOW_EDGE) {
          GUITARLog.log.info(
              currentEvent.getEventId()
                  + ","
                  + currentEvent.getWidgetId()
                  + "->"
                  + event.getEventId()
                  + ","
                  + event.getWidgetId());
        }
      }
      GUITARLog.log.info("");
    }
  }
Ejemplo n.º 8
0
  /** Just for debug */
  private void debug() {

    GUITARLog.log.info("Debugging.........");
    List<EventType> eventList = efg.getEvents().getEvent();
    for (EventType e : eventList) {
      GUITARLog.log.info("================================");
      GUITARLog.log.info("Analyzing " + e.getEventId() + "-" + e.getWidgetId());
      List<EventType> predEventList = preds.get(e);

      String sEventList = "Pred: [";
      for (EventType predEvent : predEventList) {
        sEventList += (predEvent.getEventId() + "-" + predEvent.getWidgetId() + ", ");
      }
      sEventList += "]";
      GUITARLog.log.info(sEventList);
    }

    GUITARLog.log.info("Done Debugging.........");
  }
Ejemplo n.º 9
0
  /**
   * Execute a single step in the test case
   *
   * <p>
   *
   * @param step
   * @throws ComponentNotFound
   */
  private void executeStep(StepType step) throws ComponentNotFound {

    TestStepStartEventArgs stepStartArgs = new TestStepStartEventArgs(step);

    // -----------------------
    // Monitor before step
    for (GTestMonitor aTestMonitor : lTestMonitor) {
      aTestMonitor.beforeStep(stepStartArgs);
    }

    // Events
    String sEventID = step.getEventId();
    GUITARLog.log.info("EventID: " + sEventID);

    // Get widget ID and actions
    // String sWidgetID = getWidgetID("WidgetId", sEventID);
    String sWidgetID = null;
    String sAction = null;

    List<EventType> lEvents = efg.getEvents().getEvent();

    for (EventType event : lEvents) {
      String eventID = event.getEventId();
      if (sEventID.equals(eventID)) {
        sWidgetID = event.getWidgetId();
        sAction = event.getAction();
      }
    }

    if (sWidgetID == null) {
      GUITARLog.log.error("Component ID not found");
      throw new ComponentNotFound();
    } else if (sAction == null) {
      GUITARLog.log.error("Action not found");
      throw new ComponentNotFound();
    }

    String sWindowID = getWindowName(sWidgetID);

    if (sWindowID == null) {
      GUITARLog.log.error("Window Title not found");
      throw new ComponentNotFound();
    }

    GUITARLog.log.info("Window Title: *" + sWindowID + "*");
    GUITARLog.log.info("Widget ID: *" + sWidgetID + "*");
    GUITARLog.log.info("");

    GUITARLog.log.info("Finding window *" + sWindowID + "*....");

    // TODO: Change this method to a fuzzy matching
    GWindow gWindow = monitor.getWindow(sWindowID);
    GUITARLog.log.info("FOUND");
    GUITARLog.log.info("");

    ComponentTypeWrapper comp = guiStructureAdapter.getComponentFromID(sWidgetID);

    if (comp == null) throw new ComponentNotFound();

    List<PropertyType> ID = monitor.selectIDProperties(comp.getDComponentType());
    List<PropertyTypeWrapper> IDAdapter = new ArrayList<PropertyTypeWrapper>();

    for (PropertyType p : ID) IDAdapter.add(new PropertyTypeWrapper(p));

    GComponent containter = gWindow.getContainer();

    GUITARLog.log.info("Finding widget *" + sWidgetID + "*....");

    // GUITARLog.log.debug("Componnent signature: ");
    // for (PropertyTypeWrapper p : IDAdapter) {
    // GUITARLog.log.debug(p.toString());
    // }

    GComponent gComponent = containter.getFirstChild(IDAdapter);

    if (gComponent == null) throw new ComponentNotFound();

    GUITARLog.log.info("FOUND");
    GUITARLog.log.info("Widget Title: *" + gComponent.getTitle() + "*");
    GUITARLog.log.info("");
    if (!gComponent.isEnable()) throw new ComponentDisabled();

    // Actions
    GEvent gEvent = monitor.getAction(sAction);
    List<String> parameters = step.getParameter();

    GUITARLog.log.info("Action: *" + sAction);
    GUITARLog.log.info("");

    // Optional data
    AttributesType optional = comp.getDComponentType().getOptional();
    Hashtable<String, List<String>> optionalValues = null;

    if (optional != null) {

      optionalValues = new Hashtable<String, List<String>>();
      for (PropertyType property : optional.getProperty()) {
        optionalValues.put(property.getName(), property.getValue());
      }
    }

    if (parameters == null) gEvent.perform(gComponent, optionalValues);
    else if (parameters.size() == 0) {
      gEvent.perform(gComponent, optionalValues);
    } else gEvent.perform(gComponent, parameters, optionalValues);

    // -----------------------
    // Monitor after step
    if (!lTestMonitor.isEmpty()) {
      try {
        TestStepEndEventArgs stepEndArgs =
            new TestStepEndEventArgs(
                step, gComponent.extractProperties(), gWindow.extractGUIProperties());
        for (GTestMonitor aTestMonitor : lTestMonitor) {
          aTestMonitor.afterStep(stepEndArgs);
        }
      } catch (Exception e) {
        log.error("Failed to collect post-event state", e);
      }
    }
  }
Ejemplo n.º 10
0
  /*
   * (non-Javadoc)
   *
   * @see
   * edu.umd.cs.guitar.graph.plugin.G2GPlugin#parseGraph(edu.umd.cs.guitar
   * .model.data.EFG)
   */
  @Override
  public boolean parseGraph() {
    // initialize
    parseFollowRelations();
    parseInitialEvents();

    outputGraph = factory.createEFG();
    map = factory.createMapping();

    EventsType eventList = factory.createEventsType();
    EventGraphType eventGraph = factory.createEventGraphType();

    // select interaction events
    List<EventType> lEventList = getEventList();

    // set initial events
    InitialMappingListType lInitialMappingList = factory.createInitialMappingListType();

    for (EventType event : lEventList) {
      LinkedList<EventType> pathToRoot = pathToRoot(event);

      if (pathToRoot != null) {
        pathToRoot.removeLast();
        if (pathToRoot.size() > 0) {

          event.setInitial(true);
          InitialMappingType initialMapping = factory.createInitialMappingType();

          initialMapping.setEventId(event.getEventId());

          PathType mappingPathToRoot = factory.createPathType();
          for (EventType eventToRoot : pathToRoot)
            mappingPathToRoot.getEventId().add(eventToRoot.getEventId());

          initialMapping.setPath(mappingPathToRoot);
          lInitialMappingList.getIntialMapping().add(initialMapping);
        }
      }
    }

    map.setInitialMappingList(lInitialMappingList);

    eventList.setEvent(lEventList);
    outputGraph.setEvents(eventList);

    // mapping edge
    EdgeMappingListType edgeMappingList = factory.createEdgeMappingListType();

    // build edge
    List<RowType> lRowList = new ArrayList<RowType>();
    for (EventType firstEvent : lEventList) {
      int indexFirst = lEventList.indexOf(firstEvent);
      // System.out.println("Anlyzing row: " + indexFirst);
      RowType row = factory.createRowType();

      for (EventType secondEvent : lEventList) {
        int indexSecond = lEventList.indexOf(secondEvent);

        List<EventType> path = getInteractionFreePath(firstEvent, secondEvent);
        int cellValue;

        if (path != null) {

          cellValue = 1;

          if (path.size() > 0) {
            EdgeMappingType edgeMapping = factory.createEdgeMappingType();
            edgeMapping.setSourceId(firstEvent.getEventId());
            edgeMapping.setTargetId(secondEvent.getEventId());

            PathType eventPath = factory.createPathType();

            for (EventType event : path) eventPath.getEventId().add(event.getEventId());

            edgeMapping.setPath(eventPath);
            edgeMappingList.getEdgeMapping().add(edgeMapping);
          }

        } else {
          cellValue = 0;
        }

        row.getE().add(indexSecond, cellValue);
      }

      lRowList.add(indexFirst, row);
    }

    eventGraph.setRow(lRowList);
    outputGraph.setEventGraph(eventGraph);

    map.setEdgeMappingList(edgeMappingList);

    // debug
    System.out.println("===========================");
    System.out.println("OUTPUT GRAPH");
    printGraph(outputGraph);

    return true;
  }