Search in sources :

Example 1 with ImageHelper

use of org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ImageHelper in project tracecompass by tracecompass.

the class FilterColorEditorTest method testHighlight.

/**
 * Test basic highlight
 */
@Test
public void testHighlight() {
    final Rectangle cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, SOURCE_COLUMN);
    ImageHelper before = ImageHelper.grabImage(cellBounds);
    Multiset<RGB> colorBefore = before.getHistogram();
    // Select source column and enter regex
    fTableBot.click(0, SOURCE_COLUMN);
    fBot.text().typeText("HostF\n", 100);
    // make sure selected row is not matching row
    fTableBot.select(ROW - 1);
    Multiset<RGB> colorAfter = ImageHelper.waitForNewImage(cellBounds, before).getHistogram();
    assertTrue(colorBefore.contains(fBackground));
    assertTrue(colorBefore.contains(fForeground));
    assertFalse(colorBefore.contains(fHighlight));
    assertTrue(colorAfter.contains(fBackground));
    assertTrue(colorAfter.contains(fForeground));
    assertTrue(colorAfter.contains(fHighlight));
    /*
         * Check that some background became highlighted.
         */
    assertTrue(colorAfter.count(fBackground) < colorBefore.count(fBackground));
    assertTrue(colorAfter.count(fHighlight) > colorBefore.count(fHighlight));
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) RGB(org.eclipse.swt.graphics.RGB) ImageHelper(org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ImageHelper) Test(org.junit.Test)

Example 2 with ImageHelper

use of org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ImageHelper in project tracecompass by tracecompass.

the class FilterColorEditorTest method testPreference.

/**
 * Test highlight color preference
 */
@Test
public void testPreference() {
    // change the highlight color preference
    ColorRegistry colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
    colorRegistry.put(HIGHLIGHT_COLOR_DEFINITION_ID, GREEN);
    final Rectangle cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, SOURCE_COLUMN);
    ImageHelper before = ImageHelper.grabImage(cellBounds);
    Multiset<RGB> colorBefore = before.getHistogram();
    // Select source column and enter regex
    fTableBot.click(0, SOURCE_COLUMN);
    fBot.text().typeText("HostF\n", 100);
    // make sure selected row is not matching row
    fTableBot.select(ROW - 1);
    Multiset<RGB> colorAfter = ImageHelper.waitForNewImage(cellBounds, before).getHistogram();
    assertTrue(colorBefore.contains(fBackground));
    assertTrue(colorBefore.contains(fForeground));
    assertFalse(colorBefore.contains(fHighlight));
    assertFalse(colorBefore.contains(fGreen));
    assertTrue(colorAfter.contains(fBackground));
    assertTrue(colorAfter.contains(fForeground));
    assertFalse(colorAfter.contains(fHighlight));
    assertTrue(colorAfter.contains(fGreen));
    /*
         * Check that some background became green.
         */
    assertTrue(colorAfter.count(fBackground) < colorBefore.count(fBackground));
    assertTrue(colorAfter.count(fGreen) > colorBefore.count(fGreen));
    // reset the highlight color preference
    colorRegistry.put(HIGHLIGHT_COLOR_DEFINITION_ID, fHighlight);
}
Also used : ColorRegistry(org.eclipse.jface.resource.ColorRegistry) Rectangle(org.eclipse.swt.graphics.Rectangle) RGB(org.eclipse.swt.graphics.RGB) ImageHelper(org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ImageHelper) Test(org.junit.Test)

Example 3 with ImageHelper

use of org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ImageHelper in project tracecompass by tracecompass.

the class FilterColorEditorTest method testSwitchToFilter.

/**
 * Switch to filter and back
 */
@Test
public void testSwitchToFilter() {
    Rectangle cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, TIMESTAMP_COLUMN);
    ImageHelper before = ImageHelper.grabImage(cellBounds);
    // enter regex in Timestamp column
    fTableBot.click(0, TIMESTAMP_COLUMN);
    fBot.text().typeText("00\n", 100);
    // make sure matching column is not selected
    fTableBot.select(ROW - 1);
    ImageHelper afterSearch = ImageHelper.waitForNewImage(cellBounds, before);
    // click Add as Filter
    fTableBot.click(0, 0);
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(fTableBot, "<srch>", 0, TIMESTAMP_COLUMN));
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(fTableBot, "22/22", 1, TIMESTAMP_COLUMN));
    // the bounds have changed after applying the filter
    cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, TIMESTAMP_COLUMN);
    ImageHelper afterFilter = ImageHelper.grabImage(cellBounds);
    // press DEL to clear highlighting
    fTableBot.pressShortcut(Keystrokes.DELETE);
    ImageHelper afterClear = ImageHelper.waitForNewImage(cellBounds, afterFilter);
    List<RGB> beforeLine = before.getPixelRow(2);
    List<RGB> afterSearchLine = afterSearch.getPixelRow(2);
    List<RGB> afterFilterLine = afterFilter.getPixelRow(2);
    List<RGB> afterClearLine = afterClear.getPixelRow(2);
    assertEquals(beforeLine.size(), afterSearchLine.size());
    assertEquals(beforeLine.size(), afterFilterLine.size());
    assertEquals(beforeLine.size(), afterClearLine.size());
    for (int i = 0; i < beforeLine.size(); i++) {
        RGB beforePixel = beforeLine.get(i);
        RGB afterSearchPixel = afterSearchLine.get(i);
        RGB afterFilterPixel = afterFilterLine.get(i);
        RGB afterClearPixel = afterClearLine.get(i);
        assertEquals(afterSearchPixel, afterFilterPixel);
        assertEquals(beforePixel, afterClearPixel);
        if (!afterSearchPixel.equals(fHighlight)) {
            assertEquals(beforePixel, afterSearchPixel);
        } else {
            assertNotEquals(fHighlight, beforePixel);
        }
    }
    assertEquals(afterSearchLine, afterFilterLine);
    assertEquals(beforeLine, afterClearLine);
    assertNotEquals(afterSearchLine, beforeLine);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) RGB(org.eclipse.swt.graphics.RGB) ImageHelper(org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ImageHelper) Point(org.eclipse.swt.graphics.Point) Test(org.junit.Test)

Example 4 with ImageHelper

use of org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ImageHelper in project tracecompass by tracecompass.

the class TimeGraphViewTest method testVerticalZoom.

/**
 * Test vertical zoom in and out
 */
@Test
public void testVerticalZoom() {
    resetTimeRange();
    int threshold = 10;
    SWTBotTimeGraph timegraph = fTimeGraph;
    Rectangle bounds = fBounds;
    ImageHelper ref = ImageHelper.grabImage(bounds);
    fireKeyAndWait(timegraph, bounds, false, '+', SWT.CTRL);
    fireKeyAndWait(timegraph, bounds, false, '-', SWT.CTRL);
    ImageHelper bigSmall = ImageHelper.grabImage(bounds);
    ImageHelper diff = ref.diff(bigSmall);
    // 3% of the image
    threshold = (int) (diff.getHistogram().size() * 0.03);
    List<RGB> colors = filter(diff.getHistogram(), threshold);
    assertEquals(colors.toString(), 1, colors.size());
    fireKeyAndWait(timegraph, bounds, false, '+', SWT.CTRL);
    fireKeyAndWait(timegraph, bounds, false, '+', SWT.CTRL);
    ImageHelper bigBig = ImageHelper.grabImage(bounds);
    diff = ref.diff(bigBig);
    colors = filter(diff.getHistogram(), threshold);
    assertNotEquals(colors.toString(), 1, colors.size());
    fireKeyAndWait(timegraph, bounds, false, '+', SWT.CTRL);
    fireKeyAndWait(timegraph, bounds, false, '-', SWT.CTRL);
    fireKeyAndWait(timegraph, bounds, false, '0', SWT.CTRL);
    ImageHelper bigSmallReset = ImageHelper.grabImage(bounds);
    diff = ref.diff(bigSmallReset);
    colors = filter(diff.getHistogram(), threshold);
    assertEquals(colors.toString(), 1, colors.size());
    fireKeyAndWait(timegraph, bounds, false, '-', SWT.CTRL);
    fireKeyAndWait(timegraph, bounds, false, '-', SWT.CTRL);
    ImageHelper smallSmall = ImageHelper.grabImage(bounds);
    diff = ref.diff(smallSmall);
    colors = filter(diff.getHistogram(), threshold);
    assertNotEquals(colors.toString(), 1, colors.size());
    fireKeyAndWait(timegraph, bounds, false, '-', SWT.CTRL);
    fireKeyAndWait(timegraph, bounds, false, '+', SWT.CTRL);
    fireKeyAndWait(timegraph, bounds, false, '0', SWT.CTRL);
    ImageHelper smallBigReset = ImageHelper.grabImage(bounds);
    diff = ref.diff(smallBigReset);
    colors = filter(diff.getHistogram(), threshold);
    assertEquals(colors.toString(), 1, colors.size());
}
Also used : SWTBotTimeGraph(org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotTimeGraph) Rectangle(org.eclipse.swt.graphics.Rectangle) RGB(org.eclipse.swt.graphics.RGB) Point(org.eclipse.swt.graphics.Point) ImageHelper(org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ImageHelper) Test(org.junit.Test)

Example 5 with ImageHelper

use of org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ImageHelper in project tracecompass by tracecompass.

the class TimeGraphViewTest method testLegendArrow.

/**
 * Test the legend operation for an arrow. Change sliders and reset, do not
 * change colors as there is not mock of the color picker yet
 *
 * TODO: mock color picker
 *
 * TODO: make stable
 */
@Test
public void testLegendArrow() {
    resetTimeRange();
    Rectangle bounds = fBounds;
    ImageHelper ref = ImageHelper.grabImage(bounds);
    // Set the widths to 0.25
    fViewBot.toolbarButton(SHOW_LEGEND).click();
    SWTBotShell legendShell = fBot.shell(LEGEND_NAME);
    legendShell.activate();
    SWTBot legendBot = legendShell.bot();
    assertFalse(legendBot.buttonWithId(LEGEND_ENTRY_KEY, QUOTE_LASER_UNQUOTE).isEnabled());
    int defaultValue = legendBot.scaleWithId(LEGEND_ENTRY_KEY, QUOTE_LASER_UNQUOTE).getValue();
    legendBot.scaleWithId(LEGEND_ENTRY_KEY, QUOTE_LASER_UNQUOTE).setValue(100);
    assertTrue(legendBot.buttonWithId(LEGEND_ENTRY_KEY, QUOTE_LASER_UNQUOTE).isEnabled());
    legendShell.bot().button(OK_BUTTON).click();
    fBot.waitUntil(Conditions.shellCloses(legendShell));
    resetTimeRange();
    // Take another picture
    ImageHelper thick = ImageHelper.waitForNewImage(bounds, ref);
    // Compare with the original, they should be different
    int refCount = ref.getHistogram().count(fLaser);
    int thickCount = thick.getHistogram().count(fLaser);
    assertTrue(String.format("Count of \"\"LASER\"\" (%s) did not get change despite change of width before: %d after:%d histogram:%s", fLaser, refCount, thickCount, Multisets.copyHighestCountFirst(thick.getHistogram())), thickCount > refCount);
    // reset all
    fViewBot.toolbarButton(SHOW_LEGEND).click();
    legendShell = fBot.shell(LEGEND_NAME);
    legendBot = legendShell.bot();
    assertTrue(legendBot.buttonWithId(LEGEND_ENTRY_KEY, QUOTE_LASER_UNQUOTE).isEnabled());
    legendBot.buttonWithId(LEGEND_ENTRY_KEY, QUOTE_LASER_UNQUOTE).click();
    assertEquals(defaultValue, legendBot.scaleWithId(LEGEND_ENTRY_KEY, QUOTE_LASER_UNQUOTE).getValue());
    assertFalse(legendBot.buttonWithId(LEGEND_ENTRY_KEY, QUOTE_LASER_UNQUOTE).isEnabled());
    legendBot.button(OK_BUTTON).click();
    fBot.waitUntil(Conditions.shellCloses(legendShell));
    resetTimeRange();
    // take a third picture
    ImageHelper reset = ImageHelper.waitForNewImage(bounds, thick);
    // Compare with the original, they should be the same
    int resetCount = reset.getHistogram().count(fLaser);
    assertEquals("Count of \"\"LASER\"\" did not get change despite reset of width", refCount, resetCount);
}
Also used : SWTBot(org.eclipse.swtbot.swt.finder.SWTBot) Rectangle(org.eclipse.swt.graphics.Rectangle) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) ImageHelper(org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ImageHelper) Point(org.eclipse.swt.graphics.Point) Test(org.junit.Test)

Aggregations

ImageHelper (org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ImageHelper)12 Test (org.junit.Test)11 Rectangle (org.eclipse.swt.graphics.Rectangle)10 Point (org.eclipse.swt.graphics.Point)8 RGB (org.eclipse.swt.graphics.RGB)7 SWTBot (org.eclipse.swtbot.swt.finder.SWTBot)4 SWTBotShell (org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)4 SWTBotTimeGraph (org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotTimeGraph)4 File (java.io.File)1 ArrayList (java.util.ArrayList)1 ColorRegistry (org.eclipse.jface.resource.ColorRegistry)1 SWTWorkbenchBot (org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot)1 SWTBotText (org.eclipse.swtbot.swt.finder.widgets.SWTBotText)1 SWTBotTimeGraphEntry (org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotTimeGraphEntry)1 Ignore (org.junit.Ignore)1