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