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.

88 <strong>Model</strong> Programs<br />

// ... Reactive system model program, continued<br />

static bool CalibrateEnabled()<br />

{<br />

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

&& waitfor == WaitFor.Timeout<br />

&& sensor == Sensor.OK<br />

&& phase == Phase.HandleEvent);<br />

}<br />

[Action]<br />

static void Calibrate()<br />

{<br />

double data = double.Parse(buffer);<br />

phase = Phase.WaitForEvent;<br />

}<br />

static bool CheckMessageEnabled()<br />

{<br />

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

&& waitfor == WaitFor.Message<br />

&& phase == Phase.HandleEvent);<br />

}<br />

[Action]<br />

static void CheckMessage()<br />

{<br />

double tol = 5.0;<br />

try {<br />

double data = double.Parse(buffer);<br />

if (previous == double.MaxValue) previous = data; // initialize<br />

if (Math.Abs(data - previous) < tol) {<br />

previous = data;<br />

sensor = Sensor.OK;<br />

}<br />

else sensor = Sensor.Error; // retain old previous<br />

}<br />

catch {<br />

sensor = Sensor.Error;<br />

}<br />

CancelTimer(); // cancel messageTimeout<br />

StartTimer(); // wait for next time to poll<br />

waitfor = WaitFor.Timeout;<br />

phase = Phase.WaitForEvent;<br />

}<br />

// continued ...<br />

Figure 5.14. Reactive system: model program (part 3).<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!