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.

}<br />

}<br />

Overview 39<br />

// ... continued<br />

// Handlers<br />

protected void timer_Tick(object sender, EventArgs e)<br />

{<br />

c.timer.Enabled = false; // Controller must restart timer<br />

c.ReceiveEvent(ControlEvent.Timeout, null);<br />

c.DispatchHandler();<br />

}<br />

#region Handlers for other buttons (code not shown)<br />

protected void btnExit_Click(object sender, EventArgs e)<br />

{<br />

c.ReceiveEvent(ControlEvent.Exit, null);<br />

Application.Exit();<br />

}<br />

// Run the simulation<br />

public static void Main()<br />

{<br />

Application.Run(new Simulator());<br />

}<br />

Figure 3.6. Process control simulator application with events (2).<br />

registers our method timer Tick (Figure 3.6) as a handler for this event. When the<br />

timer times out, it raises its Tick event, which causes our handler method timer Tick<br />

to execute. This machinery also ensures that events are delivered to our controller<br />

one at a time, so each event is handled before the next is delivered.<br />

In the Controller class, the DispatchHandler method is the dispatcher that selects<br />

which handler to run after an event occurs. It contains the core logic of the controller:<br />

public void DispatchHandler()<br />

{<br />

if (ResetEnabled()) Reset();<br />

else if (PollEnabled()) Poll();<br />

else if (CheckMessageEnabled()) CheckMessage();<br />

else if (ReportLostMessageEnabled()) ReportLostMessage();<br />

else if (CalibrateEnabled()) Calibrate();<br />

}<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!