/**
   * Selects specified text in specified opened editor, shows open on options via selecting Navigate
   * -> Open Hyperlink and select one of them specified by openOnOption
   *
   * @param bot
   * @param editorTitle
   * @param textToSelect
   * @param selectionOffset
   * @param selectionLength
   * @param textToSelectIndex
   * @param openOnOption
   */
  public static SWTBotEditor selectOpenOnOption(
      SWTBotExt bot,
      String editorTitle,
      String textToSelect,
      int selectionOffset,
      int selectionLength,
      int textToSelectIndex,
      String openOnOption) {
    showOpenOnOptions(
        bot, editorTitle, textToSelect, selectionOffset, selectionLength, textToSelectIndex);

    SWTBotTable table = bot.activeShell().bot().table(0);

    boolean optionFound = false;
    String foundOptions = "";

    for (int i = 0; i < table.rowCount(); i++) {
      String foundOption = table.getTableItem(i).getText();
      foundOptions = foundOptions + foundOption + ", ";
      if (foundOption.contains(openOnOption)) {
        optionFound = true;
        table.click(i, 0);
        break;
      }
    }
    foundOptions = foundOptions.substring(0, foundOptions.length() - 3);
    assertTrue(
        openOnOption
            + " was not found in open on options of "
            + textToSelect
            + " Found: "
            + foundOptions,
        optionFound);
    return bot.activeEditor();
  }
  /**
   * Returns string representing version of defined Server Runtime on rowIndex position in Defined
   * Server Runtime table
   *
   * @param bot
   * @param rowIndex
   * @return null when no server runtime is specified, "unknown when not possible to determine
   *     server runtime version" or server runtime version
   */
  public static String getDefinedServerRuntimeVersion(SWTWorkbenchBot bot, int rowIndex) {

    String result = null;

    bot.menu(IDELabel.Menu.WINDOW).menu(IDELabel.Menu.PREFERENCES).click();
    bot.shell(IDELabel.Shell.PREFERENCES).activate();
    bot.tree()
        .expandNode(IDELabel.PreferencesDialog.SERVER_GROUP)
        .select(PreferencesDialog.RUNTIME_ENVIRONMENTS);

    SWTBotTable serverRuntimesTable = bot.table();
    if (serverRuntimesTable.rowCount() > rowIndex) {
      String[] splitServerRuntimeType = serverRuntimesTable.cell(rowIndex, 1).split(" ");
      int index = 0;
      while (index < splitServerRuntimeType.length && result == null) {
        if (splitServerRuntimeType[index].length() > 0
            && splitServerRuntimeType[index].charAt(0) >= '0'
            && splitServerRuntimeType[index].charAt(0) <= '9') {
          result = splitServerRuntimeType[index].trim();
        } else {
          index++;
        }
      }
    }

    bot.button(IDELabel.Button.OK).click();

    return result;
  }
  /**
   * Returns true if runtimeName Server Runtime is defined
   *
   * @param bot
   * @param runtimeName
   * @return
   */
  public static boolean isServerRuntimeDefined(SWTWorkbenchBot bot, String runtimeName) {

    boolean serverRuntimeNotDefined = true;

    bot.menu(IDELabel.Menu.WINDOW).menu(IDELabel.Menu.PREFERENCES).click();
    bot.shell(IDELabel.Shell.PREFERENCES).activate();
    bot.tree()
        .expandNode(IDELabel.PreferencesDialog.SERVER_GROUP)
        .select(PreferencesDialog.RUNTIME_ENVIRONMENTS);

    SWTBotTable tbRuntimeEnvironments = bot.table();
    int numRows = tbRuntimeEnvironments.rowCount();
    if (numRows > 0) {
      int currentRow = 0;
      while (serverRuntimeNotDefined && currentRow < numRows) {
        if (tbRuntimeEnvironments.cell(currentRow, 0).equalsIgnoreCase(runtimeName)) {
          serverRuntimeNotDefined = false;
        } else {
          currentRow++;
        }
      }
    }

    bot.button(IDELabel.Button.OK).click();

    return !serverRuntimeNotDefined;
  }
  /** Import a gzip trace */
  @Test
  public void testGzipImport() {
    final String traceType = "Test trace : TMF Tests";
    final String tracesNode = "Traces [1]";

    /*
     * Actual importing
     */
    openImportWizard();
    selectImportFromArchive(fGzipTrace.getAbsolutePath());
    selectFolder(ROOT_FOLDER);
    SWTBotCheckBox checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
    assertFalse(checkBox.isEnabled());
    SWTBotCombo comboBox = fBot.comboBoxWithLabel(Messages.ImportTraceWizard_TraceType);
    comboBox.setSelection(traceType);
    importFinish();
    /*
     * Remove .gz extension
     */
    assertNotNull(fGzipTrace);
    String name = fGzipTrace.getName();
    assertNotNull(name);
    assertTrue(name.length() > 3);
    String traceName = name.substring(0, name.length() - 3);
    assertNotNull(traceName);
    assertFalse(traceName.isEmpty());

    /*
     * Open trace
     */
    SWTBotView projectExplorer = fBot.viewById(IPageLayout.ID_PROJECT_EXPLORER);
    projectExplorer.setFocus();
    final SWTBotTree tree = projectExplorer.bot().tree();
    /*
     * This appears to be problematic due to the length of the file name and
     * the resolution in our CI.
     */
    tree.expandNode(PROJECT_NAME, true);
    SWTBotTreeItem treeItem = tree.getTreeItem(PROJECT_NAME);
    fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(tracesNode, treeItem));
    treeItem = treeItem.getNode(tracesNode);
    fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(traceName, treeItem));
    treeItem = treeItem.getNode(traceName);
    treeItem.doubleClick();
    SWTBotUtils.waitForJobs();
    /*
     * Check results
     */
    SWTBotTable editor = fBot.activeEditor().bot().table();
    String c22 = editor.cell(2, 2);
    String c10 = editor.cell(1, 0);
    assertEquals("Type-1", c22);
    assertEquals("", c10);
  }
 public boolean selectSDK(File home) throws IOException {
   String path = home.getPath();
   int count = sdks.rowCount();
   for (int row = 0; row < count; ++row) {
     SWTBotTableItem item = sdks.getTableItem(row);
     if (path.equals(item.getText(2))) {
       item.check();
       return true;
     }
   }
   return false;
 }
  /** @throws Exception */
  private void checkTab(String tabName) throws Exception {
    SWTBotCTabItem tabItem = editor.bot().cTabItem(tabName);
    tabItem.setFocus();

    SWTBotTable table = editor.bot().table();
    SWTBotTableColumn tCol = table.header("Translation of");
    tCol.setFocus();
    tCol = table.header("Kind");
    tCol.setFocus();

    SWTBotButton bttn = editor.bot().button("Edit Source Model");
    assertFalse(bttn.isEnabled());
  }
  // DONE!
  public SWTBotGefEditPart addValidate(SWTBotGefEditPart toPart, String name, String... variables) {
    appendActivity(toPart, "Validate", name);
    SWTBot propsBot = propsView.bot();
    propsView.selectTab(1);
    propsBot.button("Add").click();

    SWTBotShell shell = bot.shell("Select Variable").activate();
    SWTBot viewBot = shell.bot();
    SWTBotTable table = viewBot.table();
    table.select(variables);
    viewBot.button("OK").click();

    save();
    SWTBotGefEditPart added = getEditPart(toPart, name);
    //		log.info("Added [part=" + added + ", name=" + name + "]");
    return added;
  }
Exemple #8
0
  /**
   * @param table
   * @param object
   * @return the table item corresponding to the object
   */
  private SWTBotTableItem getTableItem(SWTBotTable table, EObject object) {
    for (int i = 0; i < table.rowCount(); i++) {
      final SWTBotTableItem tableItem = table.getTableItem(i);
      final Object data =
          syncExec(
              new Result<Object>() {

                public Object run() {
                  return tableItem.widget.getData();
                }
              });
      if (data.equals(object)) {
        return table.getTableItem(i);
      }
    }
    return null;
  }
 /** Test color by making all events yellow */
 @Test
 public void testYellow() {
   SWTBotView viewBot = fBot.viewById(ColorsView.ID);
   viewBot.setFocus();
   final String insert = "Insert new color setting";
   final String increasePriority = "Increase priority";
   final String decreasePriority = "Decrease priority";
   final String delete = "Delete color setting";
   viewBot.toolbarButton(insert).click();
   viewBot.toolbarButton(insert).click();
   viewBot.toolbarButton(insert).click();
   viewBot.toolbarButton(insert).click();
   viewBot.toolbarButton(increasePriority).click();
   viewBot.toolbarButton(decreasePriority).click();
   viewBot.toolbarButton(delete).click();
   viewBot.bot().label(0).setFocus();
   viewBot.toolbarButton(delete).click();
   viewBot.bot().label(0).setFocus();
   viewBot.toolbarButton(delete).click();
   final RGB foreground = new RGB(0, 0, 0);
   final RGB background = new RGB(255, 255, 0);
   // Simulate the side effects of picking a color because we cannot
   // control native Color picker dialog in SWTBot.
   final ColorSetting[] cs = new ColorSetting[1];
   UIThreadRunnable.syncExec(
       new VoidResult() {
         @Override
         public void run() {
           cs[0] = new ColorSetting(foreground, background, foreground, new PassAll());
           ColorSettingsManager.setColorSettings(cs);
         }
       });
   final SWTBotTable eventsEditor = SWTBotUtils.activeEventsEditor(fBot).bot().table();
   // should fix race condition of loading the trace
   SWTBotUtils.waitForJobs();
   eventsEditor.select(2);
   final SWTBotTableItem tableItem = eventsEditor.getTableItem(2);
   RGB fgc =
       UIThreadRunnable.syncExec(
           new Result<RGB>() {
             @Override
             public RGB run() {
               return tableItem.widget.getForeground().getRGB();
             }
           });
   RGB bgc =
       UIThreadRunnable.syncExec(
           new Result<RGB>() {
             @Override
             public RGB run() {
               return tableItem.widget.getBackground().getRGB();
             }
           });
   assertEquals("Fg", foreground, fgc);
   assertEquals("Bg", background, bgc);
   // reset color settings
   UIThreadRunnable.syncExec(
       new VoidResult() {
         @Override
         public void run() {
           ColorSettingsManager.setColorSettings(new ColorSetting[0]);
         }
       });
 }
  // Verify a new configuration will copy the configuration parameters
  // of its base configuration.
  @Test
  public void t3newConfigCopiesParms() throws Exception {
    projectExplorer.bot().tree().select(projectName);
    clickContextMenu(
        projectExplorer.bot().tree().select(projectName), "Build Configurations", "Manage...");
    SWTBotShell shell = bot.shell(projectName + ": Manage Configurations");
    shell.activate();
    shell = bot.shell(projectName + ": Manage Configurations");
    shell.activate();
    SWTBotTable table = bot.table();
    assertTrue(table.containsItem("debug"));
    table.getTableItem("debug").select();
    bot.button("Set Active").click();
    bot.button("OK").click();
    // Verify the debug configuration is active and has a user parameter:
    // --enable-jeff
    openProperties("Autotools", "Configure Settings");
    SWTBotCombo configs = bot.comboBoxWithLabel("Configuration: ");
    configs.setFocus();
    String[] items = configs.items();
    for (int i = 0; i < items.length; ++i) {
      if (items[i].contains("debug") && items[i].contains("Active")) {
        configs.setSelection(i);
      }
    }
    assertTrue(configs.getText().contains("debug"));
    bot.treeWithLabel("Configure Settings").expandNode("configure").select("Advanced");
    SWTBotText text = bot.textWithLabel("Additional command-line options");
    String val = text.getText();
    assertEquals("--enable-jeff", val);
    // Verify that the build directory for the new configuration has been
    // switched to build-debug
    shell = bot.shell("Properties for " + projectName);
    shell.activate();
    bot.text().setText("");

    bot.tree().select("C/C++ Build");
    String buildDir = bot.textWithLabel("Build directory:").getText();
    assertTrue(buildDir.endsWith("build-debug"));
    // Verify the default configuration has no user setting
    bot.tree().expandNode("Autotools").select("Configure Settings");
    configs = bot.comboBoxWithLabel("Configuration: ");
    configs.setSelection("default");
    bot.treeWithLabel("Configure Settings").expandNode("configure").select("Advanced");
    text = bot.textWithLabel("Additional command-line options");
    val = text.getText();
    assertEquals("", val);
    bot.button("OK").click();
    // Build the project again and verify we get a build-debug directory
    projectExplorer.bot().tree().select(projectName);
    clickContextMenu(projectExplorer.bot().tree().select(projectName), "Build Project");
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    assertNotNull(workspace);
    IWorkspaceRoot root = workspace.getRoot();
    assertNotNull(root);
    IProject project = root.getProject(projectName);
    assertNotNull(project);
    IPath path = project.getLocation();
    // We need to wait until the config.status file is created so
    // sleep a bit and look for it...give up after 20 seconds
    File f = null;
    for (int i = 0; i < 40; ++i) {
      bot.sleep(500);
      f = new File(path.append("build-debug/src/a.out").toOSString());
      if (f.exists()) {
        break;
      }
    }
    assertTrue(f.exists());
    f = new File(path.append("build-debug/config.status").toOSString());
    assertTrue(f.exists());
    try (BufferedReader r = new BufferedReader(new FileReader(f))) {
      int ch;
      boolean optionFound = false;
      // Read config.status and look for the string --enable-jeff
      // which is a simple verification that the option was used in the
      // configure step.
      while ((ch = r.read()) != -1) {
        if (ch == '-') {
          char[] buf = new char[12];
          r.mark(100);
          int count = r.read(buf);
          if (count < 12) {
            break;
          }
          String s = new String(buf);
          if (s.equals("-enable-jeff")) {
            optionFound = true;
            break;
          } else {
            r.reset();
          }
        }
      }
      assertTrue(optionFound);
    }
    // Verify we cleaned out the top-level build directory (i.e. that there
    // is no config.status there anymore).
    path = project.getLocation().append("config.status");
    f = new File(path.toOSString());
    assertTrue(!f.exists());
    path = project.getLocation().append(".autotools");
    f = new File(path.toOSString());
    assertTrue(f.exists());
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document d = db.parse(f);
    Element e = d.getDocumentElement();
    // Get the stored configuration data
    NodeList cfgs = e.getElementsByTagName("configuration"); // $NON-NLS-1$
    assertEquals(3, cfgs.getLength());
    int foundUser = 0;
    for (int x = 0; x < cfgs.getLength(); ++x) {
      Node n = cfgs.item(x);
      NodeList l = n.getChildNodes();
      // Verify two of the user fields in .autotools file are set to
      // --enable-jeff
      for (int y = 0; y < l.getLength(); ++y) {
        Node child = l.item(y);
        if (child.getNodeName().equals("option")) { // $NON-NLS-1$
          NamedNodeMap optionAttrs = child.getAttributes();
          Node idNode = optionAttrs.getNamedItem("id"); // $NON-NLS-1$
          Node valueNode = optionAttrs.getNamedItem("value"); // $NON-NLS-1$
          assertNotNull(idNode);
          assertNotNull(valueNode);
          String id = idNode.getNodeValue();
          String value = valueNode.getNodeValue();
          if (id.equals("user")) {
            if (value.equals("--enable-jeff")) {
              ++foundUser;
            }
          }
        }
      }
    }
    assertEquals(2, foundUser);

    clickContextMenu(
        projectExplorer.bot().tree().select(projectName), "Build Configurations", "Manage...");
    shell = bot.shell(projectName + ": Manage Configurations");
    shell.activate();
    table = bot.table();
    assertTrue(table.containsItem("Build (GNU)"));
    table.getTableItem("Build (GNU)").select();
    bot.button("Set Active").click();
    bot.button("OK").click();
    bot.waitUntil(Conditions.shellCloses(shell));
  }