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 07f4aa0a68734cf92a0666f7ad852be6f078970e..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,6 +45,7 @@ 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;
@@ -132,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);
             }
         };
     }
@@ -159,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()) });
             }
         };
@@ -187,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()) });
             }
         };
@@ -307,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);
+            }
         };
     }
 
@@ -334,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
@@ -571,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;
@@ -699,4 +748,33 @@ public final class ConditionHelpers {
     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.031249 seconds and 5 git commands to generate.