Search in sources :

Example 1 with SWTBotButton

use of org.eclipse.swtbot.swt.finder.widgets.SWTBotButton in project linuxtools by eclipse.

the class TestCreateSystemtapScript method discreteXControlTests.

private static void discreteXControlTests(AbstractChartBuilder cb, int numAxisItems) {
    // Check that default range shows 100% of data.
    IAxis axis = cb.getChart().getAxisSet().getXAxis(0);
    Range range = axis.getRange();
    double scale = cb.getScale();
    double scroll = cb.getScroll();
    assertTrue(range.upper - range.lower == axis.getCategorySeries().length - 1 && range.upper - range.lower == numAxisItems - 1);
    assertTrue(scale == 1.0 && scroll == 1.0);
    // Check that scroll buttons are disabled at 100% range.
    SWTBotButton firstButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_First);
    SWTBotButton leftButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_Left);
    SWTBotButton rightButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_Right);
    SWTBotButton lastButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_Last);
    assertFalse(firstButton.isEnabled());
    assertFalse(leftButton.isEnabled());
    assertFalse(rightButton.isEnabled());
    assertFalse(lastButton.isEnabled());
    // Test zooming in. The amount of zoom is arbitrary for this test--just make sure zooming happened.
    SWTBotButton zoomInButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_ZoomIn);
    SWTBotButton zoomOutButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_ZoomOut);
    SWTBotButton allButton = bot.button(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphDiscreteXControl_All);
    assertTrue(zoomInButton.isEnabled());
    assertFalse(zoomOutButton.isEnabled());
    assertFalse(allButton.isEnabled());
    zoomInButton.click();
    assertTrue(zoomOutButton.isEnabled());
    assertTrue(allButton.isEnabled());
    // By default, zooming in should zoom in on the end of the axis (newest data).
    range = axis.getRange();
    assertTrue(range.upper == numAxisItems - 1 && range.lower > 0 && cb.getScale() < scale && cb.getScroll() == 1.0);
    // Left scrolling should now be enabled.
    assertTrue(firstButton.isEnabled());
    assertTrue(leftButton.isEnabled());
    assertFalse(rightButton.isEnabled());
    assertFalse(lastButton.isEnabled());
    // Test scrolling left. Again, the specific amount is arbitrary, just make sure scrolling happened.
    leftButton.click();
    range = axis.getRange();
    assertTrue(range.upper < numAxisItems - 1 && cb.getScroll() < scroll);
    int rstore = (int) range.lower;
    assertTrue(rightButton.isEnabled());
    assertTrue(lastButton.isEnabled());
    // Zooming out should bring the range back to 100%.
    zoomOutButton.click();
    range = axis.getRange();
    assertTrue(range.upper - range.lower == numAxisItems - 1 && cb.getScale() == 1.0 && cb.getScroll() < scroll);
    assertTrue(zoomInButton.isEnabled());
    assertFalse(zoomOutButton.isEnabled());
    assertFalse(allButton.isEnabled());
    assertFalse(firstButton.isEnabled());
    assertFalse(leftButton.isEnabled());
    assertFalse(rightButton.isEnabled());
    assertFalse(lastButton.isEnabled());
    // For convenience, zooming out after having scrolled somewhere should make zooming in
    // zoom back to the area that was scrolled to.
    scroll = cb.getScroll();
    zoomInButton.click();
    assertTrue(rstore == axis.getRange().lower && scroll == cb.getScroll());
    // Scrolling right should take the range back to the end of the axis.
    rightButton.click();
    range = axis.getRange();
    assertTrue(range.upper == numAxisItems - 1 && range.lower > 0 && cb.getScroll() > scroll);
    assertTrue(firstButton.isEnabled());
    assertTrue(leftButton.isEnabled());
    assertFalse(rightButton.isEnabled());
    assertFalse(lastButton.isEnabled());
    // and step right/left. Add a loop limit for safety.
    for (int i = 0; i < numAxisItems; i++) {
        range = axis.getRange();
        if (range.upper == range.lower) {
            break;
        }
        zoomInButton.click();
    }
    range = axis.getRange();
    assertTrue(range.upper == range.lower && range.upper == numAxisItems - 1);
    assertTrue(!zoomInButton.isEnabled());
    for (int i = 0; i < numAxisItems; i++) {
        if (axis.getRange().lower == 0) {
            break;
        }
        leftButton.click();
        assertTrue(axis.getRange().lower < range.lower);
        range = axis.getRange();
        assertEquals(range.lower, range.upper, 0.0);
    }
    assertEquals(axis.getRange().lower, 0, 0.0);
    for (int i = 0; i < numAxisItems; i++) {
        if (axis.getRange().upper == numAxisItems - 1) {
            break;
        }
        rightButton.click();
        assertTrue(axis.getRange().upper > range.upper);
        range = axis.getRange();
        assertEquals(range.lower, range.upper, 0.0);
    }
    assertEquals(axis.getRange().upper, numAxisItems - 1, 0);
    firstButton.click();
    assertEquals(axis.getRange().lower, 0, 0);
    assertFalse(firstButton.isEnabled());
    assertFalse(leftButton.isEnabled());
    assertTrue(rightButton.isEnabled());
    assertTrue(lastButton.isEnabled());
    lastButton.click();
    assertEquals(axis.getRange().upper, numAxisItems - 1, 0);
    assertTrue(firstButton.isEnabled());
    assertTrue(leftButton.isEnabled());
    assertFalse(rightButton.isEnabled());
    assertFalse(lastButton.isEnabled());
}
Also used : SWTBotButton(org.eclipse.swtbot.swt.finder.widgets.SWTBotButton) Range(org.swtchart.Range) IAxis(org.swtchart.IAxis) Point(org.eclipse.swt.graphics.Point)

Example 2 with SWTBotButton

use of org.eclipse.swtbot.swt.finder.widgets.SWTBotButton in project linuxtools by eclipse.

the class TestCreateSystemtapScript method continuousControlTests.

private static void continuousControlTests(AbstractChartBuilder cb, boolean isXAxis) {
    // Continuous scaling/scrolling is less strict/predictable than discrete scrolling,
    // so just check that the controls perform their intended actions.
    IAxis axis;
    SWTBotButton zoomInButton, zoomOutButton;
    SWTBotScale zoomScale;
    SWTBotSlider scrollBar;
    int flipSign;
    if (isXAxis) {
        axis = cb.getChart().getAxisSet().getXAxis(0);
        zoomInButton = bot.buttonWithTooltip(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphContinuousXControl_ZoomInTooltip);
        zoomOutButton = bot.buttonWithTooltip(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphContinuousXControl_ZoomOutTooltip);
        zoomScale = bot.scaleWithTooltip(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphContinuousXControl_ScaleMessage);
        scrollBar = bot.sliderWithTooltip(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphContinuousXControl_ScrollMessage);
        flipSign = 1;
    } else {
        axis = cb.getChart().getAxisSet().getYAxis(0);
        zoomInButton = bot.buttonWithTooltip(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphContinuousYControl_ZoomInTooltip);
        zoomOutButton = bot.buttonWithTooltip(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphContinuousYControl_ZoomOutTooltip);
        zoomScale = bot.scaleWithTooltip(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphContinuousYControl_ScaleMessage);
        scrollBar = bot.sliderWithTooltip(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages.GraphContinuousYControl_ScrollMessage);
        flipSign = -1;
    }
    double scale = getAxisScale(cb, isXAxis);
    double scroll = getAxisScroll(cb, isXAxis);
    int thumb = scrollBar.getThumb();
    // Default range should be 100%, so zooming out shouldn't have an effect yet.
    assertEquals(scale, 1.0, 0);
    int zoomValue = zoomScale.getValue();
    Range range = axis.getRange();
    zoomOutButton.click();
    Range range2 = axis.getRange();
    assertTrue(range.upper == range2.upper && range.lower == range2.lower && zoomScale.getValue() == zoomValue && getAxisScale(cb, isXAxis) == scale && scrollBar.getThumb() == thumb);
    // Zoom in & back out with the zoom buttons.
    zoomInButton.click();
    range2 = axis.getRange();
    assertTrue(range2.upper - range2.lower < range.upper - range.lower && flipSign * (zoomScale.getValue() - zoomValue) > 0 && getAxisScale(cb, isXAxis) < scale && scrollBar.getThumb() < thumb);
    zoomOutButton.click();
    range2 = axis.getRange();
    assertTrue(range.upper == range2.upper && range.lower == range2.lower && zoomScale.getValue() == zoomValue && getAxisScale(cb, isXAxis) == scale && scrollBar.getThumb() == thumb);
    // Zoom in with the Scale control.
    int controlRange = zoomScale.getMaximum() - zoomScale.getMinimum();
    zoomScale.setValue(zoomScale.getValue() + controlRange / 2 * flipSign);
    // Note: the charts need some time to be updated after using the scale/slider controls.
    // Sleeping for a brief moment is faster than using a bot wait condition.
    bot.sleep(100);
    range2 = axis.getRange();
    assertTrue(range2.upper - range2.lower < range.upper - range.lower && getAxisScale(cb, isXAxis) < scale && scrollBar.getThumb() < thumb);
    range = range2;
    thumb = scrollBar.getThumb();
    scale = getAxisScale(cb, isXAxis);
    zoomScale.setValue(zoomScale.getValue() - controlRange / 4 * flipSign);
    bot.sleep(100);
    range2 = axis.getRange();
    assertTrue(range2.upper - range2.lower > range.upper - range.lower && getAxisScale(cb, isXAxis) > scale && scrollBar.getThumb() > thumb);
    // Test scrolling. Don't assume an initial scroll position, as it may be changed
    // in future versions (it's more likely to change than default zoom, at least).
    thumb = scrollBar.getThumb();
    controlRange = scrollBar.getMaximum() - scrollBar.getThumb() - scrollBar.getMinimum();
    scrollBar.setSelection(controlRange / 2);
    bot.sleep(100);
    assertEquals(scrollBar.getThumb(), thumb);
    // Scroll towards origin.
    range = axis.getRange();
    scrollBar.setSelection(scrollBar.getSelection() - controlRange / 4 * flipSign);
    bot.sleep(100);
    range2 = axis.getRange();
    assertTrue(range2.upper - range2.lower == range.upper - range.lower && range2.upper < range.upper && getAxisScroll(cb, isXAxis) < scroll);
    // Scroll away from origin.
    range = range2;
    scroll = getAxisScroll(cb, isXAxis);
    scrollBar.setSelection(scrollBar.getSelection() + controlRange / 8 * flipSign);
    bot.sleep(100);
    range2 = axis.getRange();
    assertTrue(range2.upper - range2.lower == range.upper - range.lower && range2.upper > range.upper && getAxisScroll(cb, isXAxis) > scroll);
}
Also used : SWTBotScale(org.eclipse.swtbot.swt.finder.widgets.SWTBotScale) SWTBotSlider(org.eclipse.swtbot.swt.finder.widgets.SWTBotSlider) SWTBotButton(org.eclipse.swtbot.swt.finder.widgets.SWTBotButton) Range(org.swtchart.Range) IAxis(org.swtchart.IAxis) Point(org.eclipse.swt.graphics.Point)

Example 3 with SWTBotButton

use of org.eclipse.swtbot.swt.finder.widgets.SWTBotButton in project linuxtools by eclipse.

the class TestCreateSystemtapScript method testGraphErrors.

@Test
public void testGraphErrors() {
    SWTBotShell shell = prepareScript("missingColumns.stp", null);
    SWTBotButton runButton = bot.button("Run");
    SWTBotButton addButton = bot.button(Messages.SystemTapScriptGraphOptionsTab_AddGraphButton);
    SWTBotButton editButton = bot.button(Messages.SystemTapScriptGraphOptionsTab_EditGraphButton);
    SWTBotButton dupButton = bot.button(Messages.SystemTapScriptGraphOptionsTab_DuplicateGraphButton);
    SWTBotButton remButton = bot.button(Messages.SystemTapScriptGraphOptionsTab_RemoveGraphButton);
    String graphID = "org.eclipse.linuxtools.systemtap.graphing.ui.charts.scatterchartbuilder";
    // As soon as the Graphing tab is entered, no regular expression exists & nothing can be run.
    SWTBotCombo combo = bot.comboBoxWithLabel(Messages.SystemTapScriptGraphOptionsTab_regexLabel);
    assertEquals("", combo.getText());
    assertFalse(runButton.isEnabled());
    assertFalse(addButton.isEnabled());
    combo.setText("(1)(2)");
    assertEquals("(1)(2)", combo.getText());
    assertTrue(runButton.isEnabled());
    assertTrue(addButton.isEnabled());
    setupGraphWithTests("Graph", false);
    assertTrue(runButton.isEnabled());
    // Removing groups from the regex disables graphs that rely on those groups.
    combo = bot.comboBoxWithLabel(Messages.SystemTapScriptGraphOptionsTab_regexLabel);
    combo.setText("(1)");
    assertFalse(runButton.isEnabled());
    combo.setText("(1)(2)(3)");
    assertTrue(runButton.isEnabled());
    final SWTBotTable table = bot.table();
    table.select(0);
    dupButton.click();
    assertEquals(2, table.rowCount());
    assertTrue(runButton.isEnabled());
    combo.setText("(1)");
    assertFalse(runButton.isEnabled());
    for (int i = 0, n = table.rowCount(); i < n; i++) {
        String itemTitle = table.getTableItem(i).getText();
        assertTrue("Graph " + i + " should be invalid, but it's not: " + itemTitle, table.getTableItem(i).getText().contains(Messages.SystemTapScriptGraphOptionsTab_invalidGraph));
    }
    setupGraphGeneral("Safe", 1, graphID, true, false);
    assertFalse(table.getTableItem(2).getText().contains(Messages.SystemTapScriptGraphOptionsTab_invalidGraph));
    combo.setText("(1)(2)(3)");
    assertTrue(runButton.isEnabled());
    setupGraphGeneral("Unsafe", 3, graphID, true, false);
    assertTrue(runButton.isEnabled());
    combo.setText("(1)(2)");
    assertFalse(runButton.isEnabled());
    for (int i = 0, n = table.rowCount(); i < n; i++) {
        String itemTitle = table.getTableItem(i).getText();
        assertTrue("Graph " + i + " has incorrect validity: " + itemTitle, !itemTitle.contains(Messages.SystemTapScriptGraphOptionsTab_invalidGraph) || itemTitle.contains("Unsafe"));
    }
    table.select(3);
    dupButton.click();
    remButton.click();
    assertTrue(!runButton.isEnabled());
    table.select(3);
    editButton.click();
    SWTBotShell graphShell = bot.shell("Edit Graph").activate();
    SWTBotButton finishButton = bot.button("Finish");
    assertTrue(!finishButton.isEnabled());
    bot.comboBox("<Deleted>").setSelection("NA");
    finishButton.click();
    bot.waitUntil(Conditions.shellCloses(graphShell));
    shell.setFocus();
    assertTrue(runButton.isEnabled());
    // Perform tests when graphs have an invalid graphID.
    UIThreadRunnable.syncExec(() -> {
        GraphData gd = (GraphData) table.getTableItem(0).widget.getData();
        gd.graphID = "invalidID";
        table.getTableItem(0).widget.setData(gd);
    });
    // Just to refresh the dialog
    combo.setText(combo.getText().concat(" "));
    assertFalse(runButton.isEnabled());
    assertTrue(table.getTableItem(0).getText().contains(Messages.SystemTapScriptGraphOptionsTab_invalidGraphID));
    table.select(0);
    dupButton.click();
    remButton.click();
    assertFalse(runButton.isEnabled());
    assertTrue(table.getTableItem(table.rowCount() - 1).getText().contains(Messages.SystemTapScriptGraphOptionsTab_invalidGraphID));
    table.select(table.rowCount() - 1);
    editButton.click();
    graphShell = bot.shell("Edit Graph").activate();
    finishButton = bot.button("Finish");
    assertFalse(finishButton.isEnabled());
    bot.radio(0).click();
    finishButton.click();
    bot.waitUntil(Conditions.shellCloses(graphShell));
    shell.setFocus();
    assertTrue(runButton.isEnabled());
    // Removing all invalid graphs should restore validity.
    combo.setText("(1)");
    assertFalse(runButton.isEnabled());
    for (int i = table.rowCount() - 1; i >= 0; i--) {
        if (table.getTableItem(i).getText().contains(Messages.SystemTapScriptGraphOptionsTab_invalidGraph)) {
            table.select(i);
            remButton.click();
        }
    }
    assertTrue(runButton.isEnabled());
    while (table.rowCount() > 0) {
        table.select(0);
        remButton.click();
    }
    bot.button("Apply").click();
}
Also used : SWTBotCombo(org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo) SWTBotButton(org.eclipse.swtbot.swt.finder.widgets.SWTBotButton) SWTBotTable(org.eclipse.swtbot.swt.finder.widgets.SWTBotTable) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) GraphData(org.eclipse.linuxtools.systemtap.graphing.core.structures.GraphData) Point(org.eclipse.swt.graphics.Point) Test(org.junit.Test)

Example 4 with SWTBotButton

use of org.eclipse.swtbot.swt.finder.widgets.SWTBotButton in project linuxtools by eclipse.

the class TestCreateSystemtapScript method testDeleteBlankRegex.

@Test
public void testDeleteBlankRegex() {
    SWTBotShell shell = prepareScript("blank.stp", null);
    // Confirm that adding a new regex when the current one is blank has no effect.
    SWTBotCombo combo = bot.comboBoxWithLabel(Messages.SystemTapScriptGraphOptionsTab_regexLabel);
    assertEquals(2, combo.itemCount());
    combo.setSelection(1);
    assertEquals(2, combo.itemCount());
    assertEquals(0, combo.selectionIndex());
    // Confirm that adding a regex works when the current regex is not empty.
    combo.setText("(a) b (c)");
    assertEquals("(a) b (c)", combo.getText());
    combo.setSelection(1);
    assertEquals(3, combo.itemCount());
    assertEquals(1, combo.selectionIndex());
    // Confirm that a blank regex is not removed when other data is not empty.
    combo.setText("(a)");
    bot.button(Messages.SystemTapScriptGraphOptionsTab_AddGraphButton).click();
    SWTBotShell graphShell = bot.shell("Create Graph").activate();
    graphShell.setFocus();
    bot.textWithLabel("Title:").setText("Test");
    bot.button("Finish").click();
    bot.waitUntil(Conditions.shellCloses(graphShell));
    shell.setFocus();
    combo.setText("");
    assertEquals("", combo.getText());
    combo.setSelection(0);
    assertEquals(3, combo.itemCount());
    // Confirm that auto-deleting a blank regex in the middle of the regex list works properly.
    combo.setSelection(2);
    assertEquals(4, combo.itemCount());
    combo.setText("sample");
    combo.setSelection(1);
    assertEquals(4, combo.itemCount());
    SWTBotTable table = bot.table();
    SWTBotButton remButton = bot.button(Messages.SystemTapScriptGraphOptionsTab_RemoveGraphButton);
    assertTrue(!remButton.isEnabled());
    table.select(0);
    assertTrue(remButton.isEnabled());
    remButton.click();
    assertTrue(!remButton.isEnabled());
    combo.setSelection(2);
    assertEquals(3, combo.itemCount());
    assertEquals("sample", combo.getText());
    assertEquals("(a) b (c)", combo.items()[0]);
    assertEquals("sample", combo.items()[1]);
    // Confirm that auto-deleting a regex from the beginning of the list works properly.
    combo.setSelection(2);
    combo.setText("another sample");
    combo.setSelection(0);
    combo.setText("");
    combo.setSelection(1);
    assertEquals(3, combo.itemCount());
    assertEquals("sample", combo.getText());
    assertEquals("sample", combo.items()[0]);
    assertEquals("another sample", combo.items()[1]);
}
Also used : SWTBotCombo(org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo) SWTBotButton(org.eclipse.swtbot.swt.finder.widgets.SWTBotButton) SWTBotTable(org.eclipse.swtbot.swt.finder.widgets.SWTBotTable) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) Test(org.junit.Test)

Aggregations

SWTBotButton (org.eclipse.swtbot.swt.finder.widgets.SWTBotButton)4 Point (org.eclipse.swt.graphics.Point)3 SWTBotCombo (org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo)2 SWTBotShell (org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)2 SWTBotTable (org.eclipse.swtbot.swt.finder.widgets.SWTBotTable)2 Test (org.junit.Test)2 IAxis (org.swtchart.IAxis)2 Range (org.swtchart.Range)2 GraphData (org.eclipse.linuxtools.systemtap.graphing.core.structures.GraphData)1 SWTBotScale (org.eclipse.swtbot.swt.finder.widgets.SWTBotScale)1 SWTBotSlider (org.eclipse.swtbot.swt.finder.widgets.SWTBotSlider)1