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.

92 <strong>Model</strong> Programs<br />

}<br />

}<br />

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

static bool CommandEnabled()<br />

{<br />

return (phase == Phase.WaitForEvent);<br />

}<br />

[Action]<br />

static void Command()<br />

{<br />

cevent = ControlEvent.Command;<br />

phase = Phase.HandleEvent;<br />

}<br />

// Helpers for enabling events<br />

static void PollSensor() { MessageRequested = true; }<br />

static void ResetSensor() { MessageRequested = true; }<br />

static void StartTimer() { TimeoutScheduled = true; }<br />

static void CancelTimer() { TimeoutScheduled = false; }<br />

Figure 5.18. Reactive system: model program (part 7).<br />

delivered. TimeoutMsgLate models what happens when the message is delayed; it<br />

leaves MessageRequested == true so the message can be delivered later.<br />

The Message event has a Domain attribute for the Messages method that returns<br />

the set containing the two message values, InRange and OutOfRange. This ensures<br />

that the buffer and previous data state variables can have only those two values.<br />

The four helper methods PollSensor, ResetSensor, StartTimer, and CancelTimer<br />

are called by the handlers. They model commands to the sensor and timer by<br />

assigning MessageRequested and TimeoutRequested.<br />

5.8 Other languages and tools<br />

The concepts taught in this chapter are common to many model-based testing and<br />

analysis systems, not just the library and tools we use. <strong>Model</strong>s store state and execute<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!