27.07.2013 Views

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

40 <strong>Why</strong> <strong>We</strong> <strong>Need</strong> <strong>Model</strong>-<strong>Based</strong> Analysis<br />

The dispatcher is a collection of if statements. In the first if statement, Reset() is<br />

the call to the handler and ResetEnabled() is the guard, a Boolean expression that<br />

must be true when the handler is invoked. A handler whose guard is true is said to<br />

be enabled. The design logic of the controller described in Section 3.1 is achieved<br />

by coding the guards and the bodies of the handlers. For example, here is the guard<br />

for the Reset handler:<br />

bool ResetEnabled()<br />

{<br />

return (cevent == ControlEvent.Timeout<br />

&& waitfor == WaitFor.Timout && sensor == Sensor.Error);<br />

}<br />

This guard causes the program to invoke the Reset handler when the time-out event<br />

occurs, provided that the control program is waiting for a time-out and the sensor is<br />

considered to be erroneous. In contrast, here is the guard for the Poll handler:<br />

bool PollEnabled()<br />

{<br />

return (cevent == ControlEvent.Timeout<br />

&& waitfor == WaitFor.Timeout && sensor == Sensor.OK);<br />

}<br />

This guard is similar to the previous guard, but it invokes Poll (instead of Reset)<br />

after the time-out event when the sensor is considered to be working correctly.<br />

Notice that different handlers might be invoked after the same event, depending on<br />

the values of other variables. That is why we must provide a dispatcher, instead of<br />

simply associating each handler with an event.<br />

Each handler assigns some of the variables that are tested by the guards. Here<br />

Reset assigns waitfor to indicate that the program is now waiting for a message<br />

(instead of a time-out).<br />

void Reset()<br />

{<br />

Console.WriteLine(" Reset");<br />

ResetSensor(); // send reset command to sensor<br />

StartTimer(MessageTimeout); // wait for response from sensor<br />

waitfor = WaitFor.Message;<br />

}<br />

Also, the call to ResetSensor commands the sensor to reset, which should cause<br />

another message event soon. But if no message arrives – if the sensor does not<br />

more free ebooks download links at:<br />

http://www.ebook-x.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!