Skip to main content
summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian W. Damus2014-06-05 21:32:34 +0000
committerChristian W. Damus2014-06-05 21:32:34 +0000
commitf91c173bebb38d1d488baecc1e2fafc79e1d4ea1 (patch)
treedba3ad97328530328c83d8128287fbfb4de8ef5a /tests
parent7a51182bfb865b2e113b9013ff03c25d2b80d6ca (diff)
downloadorg.eclipse.papyrus-f91c173bebb38d1d488baecc1e2fafc79e1d4ea1.tar.gz
org.eclipse.papyrus-f91c173bebb38d1d488baecc1e2fafc79e1d4ea1.tar.xz
org.eclipse.papyrus-f91c173bebb38d1d488baecc1e2fafc79e1d4ea1.zip
[Tests] Fix an NPE in sequence diagram tests
Diffstat (limited to 'tests')
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/PopupUtil.java54
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGuardVisibility_402966.java36
2 files changed, 69 insertions, 21 deletions
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/PopupUtil.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/PopupUtil.java
index 628c9886b50..17abec95063 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/PopupUtil.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/PopupUtil.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
+ * Copyright (c) 2012, 2014 CEA LIST and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,6 +9,7 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
+ * Christian W. Damus (CEA) - fixing issues in sequence diagram test execution
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.tests.bug;
@@ -17,6 +18,7 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
@@ -124,9 +126,9 @@ public class PopupUtil {
currentContextMenu = menu;
click(menu, clickMenuIndex);
menuPopup = true;
- }
- if(event.type == SWT.Hide) {
+ } else if((event.type == SWT.Hide) && (menu == currentContextMenu)) {
currentContextMenu = null;
+ menuPopup = false;
}
}
}
@@ -169,19 +171,28 @@ public class PopupUtil {
public void handleEvent(Event event) {
if(event.widget instanceof Shell) {
Shell shell = (Shell)event.widget;
+ Button defaultButton = shell.isDisposed() ? null : shell.getDefaultButton();
waitForComplete();
- notifyEvent(shell.getDefaultButton(), SWT.Selection);
+
+ if((defaultButton != null) && !defaultButton.isDisposed()) {
+ notifyEvent(defaultButton, SWT.Selection);
+ }
}
}
};
+ private static volatile boolean dialogCloseHandlerEngaged = false;
+
public static void addDialogCloseHandler() {
- Display.getDefault().syncExec(new Runnable() {
+ if(!dialogCloseHandlerEngaged) {
+ Display.getDefault().syncExec(new Runnable() {
- public void run() {
- Display.getDefault().addFilter(SWT.Show, dialogCloseHandler);
- }
- });
+ public void run() {
+ Display.getDefault().addFilter(SWT.Show, dialogCloseHandler);
+ dialogCloseHandlerEngaged = true;
+ }
+ });
+ }
}
public static void removeDialogCloseHandler() {
@@ -189,7 +200,32 @@ public class PopupUtil {
public void run() {
Display.getDefault().removeFilter(SWT.Show, dialogCloseHandler);
+ dialogCloseHandlerEngaged = false;
}
});
}
+
+ /**
+ * Runs the specified {@code runnable}, ensuring that during its execution any dialogs that are opened are not automatically closed
+ * but are managed from within the {@code runnable}.
+ *
+ * @param runnable
+ * a runnable that deliberately opens and manages dialogs
+ */
+ public static void runWithDialogs(Runnable runnable) {
+ if(!dialogCloseHandlerEngaged) {
+ // Just run it
+ runnable.run();
+ } else {
+ // First, disengage the dialog close handler
+ removeDialogCloseHandler();
+
+ try {
+ runnable.run();
+ } finally {
+ // Re-engage the handler
+ addDialogCloseHandler();
+ }
+ }
+ }
}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGuardVisibility_402966.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGuardVisibility_402966.java
index d9562033cd1..bef75e4b036 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGuardVisibility_402966.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGuardVisibility_402966.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010 CEA
+ * Copyright (c) 2010, 2014 Soyatec, CEA, and others
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,6 +9,7 @@
*
* Contributors:
* Soyatec - Initial API and implementation
+ * Christian W. Damus (CEA) - fixing issues in sequence diagram test execution
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.tests.bug.m7;
@@ -33,6 +34,7 @@ import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CustomInteractionOper
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
import org.eclipse.papyrus.uml.diagram.sequence.tests.ISequenceDiagramTestsConstants;
+import org.eclipse.papyrus.uml.diagram.sequence.tests.bug.PopupUtil;
import org.eclipse.papyrus.uml.diagram.sequence.util.InteractionOperandModelElementFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
@@ -71,17 +73,27 @@ public class TestGuardVisibility_402966 extends AbstractNodeTest {
@Test
public void testPreferencePage() {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(shell, "org.eclipse.papyrus.uml.diagram.sequence.preferences.InteractionOperandPreferencePage", null, null);
- dialog.setBlockOnOpen(false);
- dialog.open();
- IPreferencePage page = (IPreferencePage)dialog.getSelectedPage();
- Control control = page.getControl();
- Control group = getControl((Composite)control, Group.class, "Guard", SWT.NONE);
- assertNotNull("Preference Item Guard Group: ", group);
- Button checkbox = (Button)getControl((Composite)group, Button.class, "Show", SWT.CHECK);
- assertNotNull("Preference Item Visibility CheckBox: ", checkbox);
- assertEquals("Default value of Guard Visibility: ", true, checkbox.getSelection());
- dialog.close();
+ final PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(shell, "org.eclipse.papyrus.uml.diagram.sequence.preferences.InteractionOperandPreferencePage", null, null);
+
+ PopupUtil.runWithDialogs(new Runnable() {
+
+ public void run() {
+ dialog.setBlockOnOpen(false);
+ dialog.open();
+
+ try {
+ IPreferencePage page = (IPreferencePage)dialog.getSelectedPage();
+ Control control = page.getControl();
+ Control group = getControl((Composite)control, Group.class, "Guard", SWT.NONE);
+ assertNotNull("Preference Item Guard Group: ", group);
+ Button checkbox = (Button)getControl((Composite)group, Button.class, "Show", SWT.CHECK);
+ assertNotNull("Preference Item Visibility CheckBox: ", checkbox);
+ assertEquals("Default value of Guard Visibility: ", true, checkbox.getSelection());
+ } finally {
+ dialog.close();
+ }
+ }
+ });
}
private Control getControl(Composite parent, Class<?> controlType, String name, int style) {

Back to the top