|
Added
Link Here
|
| 0 |
- |
1 |
/******************************************************************************* |
|
|
2 |
* Copyright (c) 2012 Rüdiger Herrmann and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* Rüdiger Herrmann - initial API and implementation |
| 10 |
******************************************************************************/ |
| 11 |
package org.eclipse.jface.tests.dialogs; |
| 12 |
|
| 13 |
import junit.framework.TestCase; |
| 14 |
|
| 15 |
import org.eclipse.core.runtime.IStatus; |
| 16 |
import org.eclipse.core.runtime.Status; |
| 17 |
import org.eclipse.jface.dialogs.StatusDialog; |
| 18 |
import org.eclipse.swt.custom.CLabel; |
| 19 |
import org.eclipse.swt.widgets.Composite; |
| 20 |
import org.eclipse.swt.widgets.Control; |
| 21 |
import org.eclipse.swt.widgets.Shell; |
| 22 |
|
| 23 |
public class StatusDialogTest extends TestCase { |
| 24 |
|
| 25 |
private static final String PLUGIN_ID = "org.eclipse.ui.tests"; |
| 26 |
|
| 27 |
private Shell shell; |
| 28 |
|
| 29 |
public void testEscapeAmpesandInStatusLabelBug395426() { |
| 30 |
TestableStatusDialog dialog = new TestableStatusDialog(shell); |
| 31 |
dialog.open(); |
| 32 |
dialog.updateStatus(new Status(IStatus.ERROR, PLUGIN_ID, "&")); |
| 33 |
CLabel statusLabel = findStatusLabel(dialog.getShell()); |
| 34 |
assertEquals( "&&", statusLabel.getText()); |
| 35 |
} |
| 36 |
|
| 37 |
@Override |
| 38 |
protected void setUp() throws Exception { |
| 39 |
shell = new Shell(); |
| 40 |
} |
| 41 |
|
| 42 |
@Override |
| 43 |
protected void tearDown() throws Exception { |
| 44 |
shell.dispose(); |
| 45 |
} |
| 46 |
|
| 47 |
private CLabel findStatusLabel(Composite parent) { |
| 48 |
CLabel result = null; |
| 49 |
Control[] children = parent.getChildren(); |
| 50 |
for (int i = 0; i < children.length; i++) { |
| 51 |
if (children[i] instanceof CLabel) { |
| 52 |
result = (CLabel) children[i]; |
| 53 |
} |
| 54 |
} |
| 55 |
if (result == null) { |
| 56 |
for (int i = 0; i < children.length; i++) { |
| 57 |
if (children[i] instanceof Composite) { |
| 58 |
result = findStatusLabel((Composite) children[i]); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
return result; |
| 63 |
} |
| 64 |
|
| 65 |
public class TestableStatusDialog extends StatusDialog { |
| 66 |
|
| 67 |
public TestableStatusDialog(Shell parent) { |
| 68 |
super(parent); |
| 69 |
setBlockOnOpen(false); |
| 70 |
} |
| 71 |
|
| 72 |
@Override |
| 73 |
protected void updateStatus(IStatus status) { |
| 74 |
super.updateStatus(status); |
| 75 |
} |
| 76 |
} |
| 77 |
} |