How to test the ControlDecoration? [message #43100] |
Mon, 13 July 2009 09:28  |
Eclipse User |
|
|
|
If the product code use ControlDecoration to show the hover text besides a
text control, does SWTBot support testing it? If support, which API should
I use? Thanks in advance!
|
|
|
|
|
|
|
Re: How to test the ControlDecoration? [message #44964 is a reply to message #44936] |
Wed, 22 July 2009 17:11  |
Eclipse User |
|
|
|
P.S. Here is a sketch of a class that encapsulates this (assumes the control
has its decoration in getData("CONTROL_DECORATION") and uses reflection for
checking if the decoration is visible):
public class SWTBotControlDecoration {
private final AbstractSWTBot<? extends Control> mControl;
private final Field mVisibleField;
public SWTBotControlDecoration(AbstractSWTBot<? extends Control>
control) throws Exception {
mControl = control;
mVisibleField =
ControlDecoration.class.getDeclaredField("visible");
mVisibleField.setAccessible(true);
}
public Image getImage() {
return UIThreadRunnable.syncExec(mControl.display, new
Result<Image>() {
@Override
public Image run() {
return getDecoration().getImage();
}
});
}
public boolean isVisible() throws Throwable {
return UIThreadRunnable.syncExec(mControl.display, new
Result<Boolean>() {
@Override
public Boolean run() {
try {
return mVisibleField.getBoolean(getDecoration());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
private ControlDecoration getDecoration() {
return (ControlDecoration)
mControl.widget.getData("CONTROL_DECORATION");
}
}
"Will Horn" <will.horn@gmail.com> wrote in message
news:h47sv3$61m$1@build.eclipse.org...
> Thanks Kay, that is a great idea. I filed
> http://bugs.eclipse.org/bugs/284330 to request an isVisible API from
> ControlDecoration to avoid subclassing.
>
> "Kay-Uwe Graw" <kugraw@web.de> wrote in message
> news:58debefc26517611b39b79dbcd06a16b$1@www.eclipse.org...
>> In one of my project I had to solve the same problem. I wanted to write a
>> test, which checks whether the (required) decorators are visible or not.
>> I used the following approach.
>>
>> 1. Write your own CustomDecoration which extends ControlDecoration to
>> access the current state of the decoration, e.g. I added a isShow method,
>> to test whether the decoration is visible or not.
>>
>> 2. In your application code put the CustomDecoration object into the
>> widget with setData.("DECORATION_KEY", CustomDecoration):
>>
>> 3. In your swtbot test code write a utility method which uses a
>> UIRunnable to extract the CustomDecoration from the AbstractSWTBot object
>> and which calls the corresponding method, e.g. isShow.
>>
>> Kay
>>
>
|
|
|
Powered by
FUDForum. Page generated in 0.07579 seconds