Skip to content

Commit

Permalink
fixes catalog tests (remote demo WMS catalog changed)
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Gasdorf <[email protected]>
  • Loading branch information
fgdrf committed Jul 4, 2020
1 parent aeadbd1 commit 85d7690
Show file tree
Hide file tree
Showing 3 changed files with 244 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,124 +17,123 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;

/**
* This class is insane the good part is the push and findbuttons as helpers for testing.
*
*/
public class DialogDriver extends Job {

public static long DELAY = 100;

Dialog dialog;

Object[] actions;

/**
* This should be null if no errors occurred otherwise there should be debug
* message
*/
public String error;

public DialogDriver(Dialog dialog, Object[] actions) {
super("driver"); //$NON-NLS-1$

this.dialog = dialog;
this.actions = actions;
}

@Override
protected IStatus run(IProgressMonitor monitor) {
try {
final ArrayList<Boolean> l = new ArrayList<Boolean>();
l.add(true);

while (l.get(0)) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
l.set(0, dialog.getShell() == null
|| dialog.getShell().isDisposed()
|| !dialog.getShell().isVisible());
}
});
Thread.sleep(DELAY);
}

for (int i = 0; i < actions.length; i++) {
final Object action = actions[i];
dialog.getShell().getDisplay().syncExec(new Runnable() {
public void run() {
if (action instanceof Assertion)
((Assertion) action).run();
else if (action instanceof Runnable)
((Runnable) action).run();
else if (action instanceof Integer)
pushButton(dialog, ((Integer) action).intValue());

}
});

Thread.sleep(DELAY);
}

}

catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return Status.OK_STATUS;
}

public static void pushButton(Dialog dialog, int id) {
Shell shell = dialog.getShell();
Button button = findButton(shell.getChildren(), id, shell);
if( !button.isEnabled() )
throw new RuntimeException("Error button to press is not enabled"); //$NON-NLS-1$
button.notifyListeners(SWT.Selection, new Event());
}

public static Button findButton(Dialog dialog, int id) {
Shell shell = dialog.getShell();
Button found = findButton(shell.getChildren(), id, shell);
if (found != null)
return found;

Display display = Display.getCurrent();
shell = display.getActiveShell();
found = findButton(shell.getChildren(), id, shell);
if (found != null)
return found;

Shell[] shells = display.getShells();
for (Shell shell2 : shells) {
found = findButton(shell2.getChildren(), id, shell2);
if (found != null)
return found;
}
return null;
}

public static Button findButton(Control[] children, int id, Shell shell) {
if (((Integer) shell.getDefaultButton().getData()).intValue() == id)
return shell.getDefaultButton();

for (Control child : children) {
if (child instanceof Button) {
Button button = (Button) child;
Object data = button.getData();
if (data != null) {
if (((Integer) data).intValue() == id)
return button;
}
}
if (child instanceof Composite) {
Composite composite = (Composite) child;
Button button = findButton(composite.getChildren(), id, shell);
if (button != null)
return button;
}
}
return null;
}
public static long DELAY = 100;

Dialog dialog;

Object[] actions;

/**
* This should be null if no errors occurred otherwise there should be debug message
*/
public String error;

public DialogDriver(Dialog dialog, Object[] actions) {
super("driver"); //$NON-NLS-1$

this.dialog = dialog;
this.actions = actions;
}

@Override
protected IStatus run(IProgressMonitor monitor) {
try {
final ArrayList<Boolean> l = new ArrayList<Boolean>();
l.add(true);

while (l.get(0)) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
l.set(0, dialog.getShell() == null || dialog.getShell().isDisposed()
|| !dialog.getShell().isVisible());
}
});
Thread.sleep(DELAY);
}

for (int i = 0; i < actions.length; i++) {
final Object action = actions[i];
dialog.getShell().getDisplay().syncExec(new Runnable() {
public void run() {
if (action instanceof Assertion)
((Assertion) action).run();
else if (action instanceof Runnable)
((Runnable) action).run();
else if (action instanceof Integer)
pushButton(dialog, ((Integer) action).intValue());

}
});

Thread.sleep(DELAY);
}

}

catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return Status.OK_STATUS;
}

public static void pushButton(Dialog dialog, int id) {
Shell shell = dialog.getShell();
Button button = findButton(shell.getChildren(), id, shell);
if (!button.isEnabled())
throw new RuntimeException("Error button to press is not enabled"); //$NON-NLS-1$
button.notifyListeners(SWT.Selection, new Event());
}

public static Button findButton(Dialog dialog, int id) {
Shell shell = dialog.getShell();
Button found = findButton(shell.getChildren(), id, shell);
if (found != null)
return found;

Display display = Display.getCurrent();
shell = display.getActiveShell();
found = findButton(shell.getChildren(), id, shell);
if (found != null)
return found;

Shell[] shells = display.getShells();
for (Shell shell2 : shells) {
found = findButton(shell2.getChildren(), id, shell2);
if (found != null)
return found;
}
return null;
}

public static Button findButton(Control[] children, int id, Shell shell) {
if (((Integer) shell.getDefaultButton().getData()).intValue() == id)
return shell.getDefaultButton();

for (Control child : children) {
if (child instanceof Button) {
Button button = (Button) child;
Object data = button.getData();
if (data != null) {
if (((Integer) data).intValue() == id)
return button;
}
}
if (child instanceof Composite) {
Composite composite = (Composite) child;
Button button = findButton(composite.getChildren(), id, shell);
if (button != null)
return button;
}
}
return null;
}

}
Loading

0 comments on commit 85d7690

Please sign in to comment.