Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » How to test the ControlDecoration?
How to test the ControlDecoration? [message #43100] Mon, 13 July 2009 13:28 Go to next message
intothephone intothephone is currently offline intothephone intothephoneFriend
Messages: 14
Registered: July 2009
Junior Member
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 #43206 is a reply to message #43100] Mon, 13 July 2009 22:05 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
On 13/7/09 18:58, Jerome wrote:
> 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!
>

Short answer: This should probably be tested using using a mock.

Long answer:

The ControlDecoration seems be an ugly untestable mess that creates an
empty 'hover shell' on which things are drawn. Yes as in literally draw
on a blank canvas. See the constructor in the ControlDecorator#Hover
class for the paint listener that uses the graphic canvas.

hoverShell.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent pe) {
pe.gc.drawText(text, hm, hm);
if (!MAC) {
pe.gc.drawPolygon(getPolygon(true));
}
}
});


--
Ketan
http://studios.thoughtworks.com/twist | http://twitter.com/ketanpkr
Re: How to test the ControlDecoration? [message #43239 is a reply to message #43206] Mon, 13 July 2009 23:06 Go to previous messageGo to next message
Benjamin Muskalla is currently offline Benjamin MuskallaFriend
Messages: 338
Registered: July 2009
Senior Member
Ketan,

I think the code you mentioned is only for the cartoon-style form of the
"tooltip" shell. This is something which should be tested by JFace - not
the application developers.

I think it will be much more interesting to test that the decoration
appears in a test scenario. You may check the visible flag if there is
any way to access it outside. Or even the shouldShow method.

Greets
Ben

Ketan Padegaonkar wrote:
> On 13/7/09 18:58, Jerome wrote:
>> 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!
>>
>
> Short answer: This should probably be tested using using a mock.
>
> Long answer:
>
> The ControlDecoration seems be an ugly untestable mess that creates an
> empty 'hover shell' on which things are drawn. Yes as in literally draw
> on a blank canvas. See the constructor in the ControlDecorator#Hover
> class for the paint listener that uses the graphic canvas.
>
> hoverShell.addPaintListener(new PaintListener() {
> public void paintControl(PaintEvent pe) {
> pe.gc.drawText(text, hm, hm);
> if (!MAC) {
> pe.gc.drawPolygon(getPolygon(true));
> }
> }
> });
>
>


--
Benjamin Muskalla | EclipseSource Karlsruhe
http://www.eclipsesource.com | http://twitter.com/eclipsesource
Re: How to test the ControlDecoration? [message #43364 is a reply to message #43239] Tue, 14 July 2009 07:39 Go to previous messageGo to next message
Kay-Uwe Graw is currently offline Kay-Uwe GrawFriend
Messages: 24
Registered: July 2009
Junior Member
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
Re: How to test the ControlDecoration? [message #44936 is a reply to message #43364] Wed, 22 July 2009 20:31 Go to previous messageGo to next message
Will Horn is currently offline Will HornFriend
Messages: 265
Registered: July 2009
Senior Member
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
>
Re: How to test the ControlDecoration? [message #44964 is a reply to message #44936] Wed, 22 July 2009 21:11 Go to previous message
Will Horn is currently offline Will HornFriend
Messages: 265
Registered: July 2009
Senior Member
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
>>
>
Previous Topic:select a tree node and its child
Next Topic:Target Executable from the Command Line
Goto Forum:
  


Current Time: Wed Apr 24 22:44:44 GMT 2024

Powered by FUDForum. Page generated in 0.03078 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top