tmf.swtbot: Add a failure message to 'isTableCellFilled'
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.swtbot.tests / shared / org / eclipse / tracecompass / tmf / ui / swtbot / tests / shared / ConditionHelpers.java
index 366fb05a0a70f360d1134397aaf32a71f6780b50..aa58f69fbfea8e74ffaabb75239412808083ac3c 100644 (file)
@@ -18,6 +18,7 @@ import static org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory.wi
 
 import java.util.Arrays;
 import java.util.List;
+import java.util.regex.Pattern;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jface.viewers.StructuredSelection;
@@ -44,9 +45,11 @@ import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
 import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
+import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.TmfXYChartViewer;
 import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView;
 import org.eclipse.ui.IEditorReference;
 import org.hamcrest.Matcher;
+import org.swtchart.Chart;
 
 /**
  * Is a tree node available
@@ -131,7 +134,7 @@ public final class ConditionHelpers {
 
             @Override
             public String getFailureMessage() {
-                return NLS.bind("No child of table {0} found with text '{1}'.", table, name);
+                return NLS.bind("No child of table {0} found with text ''{1}''.", table, name);
             }
         };
     }
@@ -158,7 +161,7 @@ public final class ConditionHelpers {
 
             @Override
             public String getFailureMessage() {
-                return NLS.bind("No child of tree item {0} found with text '{1}'. Child items: {2}",
+                return NLS.bind("No child of tree item {0} found with text ''{1}''. Child items: {2}",
                         new String[] { treeItem.toString(), name, Arrays.toString(treeItem.getItems()) });
             }
         };
@@ -186,7 +189,7 @@ public final class ConditionHelpers {
 
             @Override
             public String getFailureMessage() {
-                return NLS.bind("Child of tree item {0} found with text '{1}' not removed. Child items: {2}",
+                return NLS.bind("Child of tree item {0} found with text ''{1}'' not removed. Child items: {2}",
                         new String[] { treeItem.toString(), String.valueOf(length), Arrays.toString(treeItem.getItems()) });
             }
         };
@@ -306,6 +309,15 @@ public final class ConditionHelpers {
                 }
                 return false;
             }
+
+            @Override
+            public String getFailureMessage() {
+                String cell = table.cell(row, column);
+                if (cell == null) {
+                    return NLS.bind("Cell absent, expected: {0}", content);
+                }
+                return NLS.bind("Cell content: {0} expected: {1}", cell, content);
+            }
         };
     }
 
@@ -333,7 +345,7 @@ public final class ConditionHelpers {
             fParentItem = parentItem;
             fName = name;
             /* Project element labels may have count suffix */
-            fRegex = name + "(\\s\\[(\\d)+\\])?";
+            fRegex = Pattern.quote(name) + "(\\s\\[(\\d)+\\])?";
         }
 
         @Override
@@ -570,6 +582,44 @@ public final class ConditionHelpers {
         return new TimeGraphIsReadyCondition(view, selectionRange, visibleTime);
     }
 
+    private static class XYViewerIsReadyCondition extends DefaultCondition  {
+
+        private TmfXYChartViewer fViewer;
+        private String fFailureMessage;
+
+        private XYViewerIsReadyCondition(TmfXYChartViewer view) {
+            fViewer = view;
+        }
+
+        @Override
+        public boolean test() throws Exception {
+
+            if (fViewer.isDirty()) {
+                fFailureMessage = "Time graph is dirty";
+                return false;
+            }
+            return true;
+        }
+
+        @Override
+        public String getFailureMessage() {
+            return fFailureMessage;
+        }
+    }
+
+    /**
+     *
+     * Wait until the XY chart viewer is ready. The XY chart viewer is
+     * considered ready when it is not updating.
+     *
+     * @param viewer
+     *            the XY chart viewer
+     * @return ICondition for verification
+     */
+    public static ICondition xyViewerIsReadyCondition(TmfXYChartViewer viewer) {
+        return new XYViewerIsReadyCondition(viewer);
+    }
+
     private static class NumberOfEventsCondition extends DefaultCondition {
 
         private ITmfTrace fTrace;
@@ -657,4 +707,74 @@ public final class ConditionHelpers {
             return fEditor;
         }
     }
+
+    private static class NumberOfSeries extends DefaultCondition {
+        private String fFailureMessage;
+        private Chart fChart;
+        private final int fNumberOfSeries;
+
+        public NumberOfSeries(Chart chart, int numberOfSeries) {
+            fChart = chart;
+            fNumberOfSeries = numberOfSeries;
+        }
+
+        @Override
+        public boolean test() throws Exception {
+            int length = fChart.getSeriesSet().getSeries().length;
+            if (length != fNumberOfSeries){
+                fFailureMessage = "Chart did not contain the expected number series. Actual " + length + ", expected " + fNumberOfSeries;
+                return false;
+            }
+
+            return true;
+        }
+
+        @Override
+        public String getFailureMessage() {
+            return fFailureMessage;
+        }
+    }
+
+    /**
+     * Wait until the chart has the specified number of series.
+     *
+     * @param chart
+     *            the chart
+     * @param numberOfSeries
+     *            the number of expected series
+     *
+     * @return ICondition for verification
+     */
+    public static ICondition numberOfSeries(Chart chart, int numberOfSeries) {
+        return new NumberOfSeries(chart, numberOfSeries);
+    }
+
+    /**
+     * Condition to check if the tree item has children
+     *
+     * @param treeItem
+     *            the tree item that should have children
+     * @return ICondition for verification
+     */
+    public static ICondition treeItemHasChildren(SWTBotTreeItem treeItem) {
+        return new TreeItemHasChildren(treeItem);
+    }
+
+    private static final class TreeItemHasChildren extends DefaultCondition {
+        private SWTBotTreeItem fTreeItem;
+
+        public TreeItemHasChildren(SWTBotTreeItem treeItem) {
+            fTreeItem = treeItem;
+        }
+
+        @Override
+        public boolean test() throws Exception {
+            return fTreeItem.getItems().length > 0;
+        }
+
+        @Override
+        public String getFailureMessage() {
+            return NLS.bind("No child of tree item {0} found.", new String[] { fTreeItem.toString() });
+        }
+    }
 }
This page took 0.027992 seconds and 5 git commands to generate.