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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Overview 35<br />

namespace ReactiveImpl<br />

{<br />

using System;<br />

public enum ControlEvent { Timeout, Message, Command, Exit }<br />

public enum WaitFor { Timeout, Message }<br />

public enum Sensor { OK, Error }<br />

public class Controller<br />

{<br />

public const int MessageTimeout = 3000; // msec, plenty of time<br />

public const int PollingInterval = 3000; // msec<br />

ControlEvent cevent;<br />

WaitFor waitfor = WaitFor.Timeout; // enable Reset<br />

Sensor sensor<br />

string buffer;<br />

= Sensor.Error; // enable Reset<br />

double previous = Double.MaxValue; // missing value flag<br />

public System.Windows.Forms.Timer timer =<br />

new System.Windows.Forms.Timer();<br />

public void ReceiveEvent(ControlEvent cevent, string buffer)<br />

{<br />

bool msgevent = (cevent == ControlEvent.Message);<br />

Console.WriteLine("?{0}{1}, {2}, {3}",<br />

cevent, msgevent ? " ’"+buffer+"’" : "",<br />

waitfor, sensor);<br />

this.cevent = cevent;<br />

if (msgevent) this.buffer = buffer; // else ignore buffer arg.<br />

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

// to be continued ...<br />

Figure 3.2. Process controller class with dispatcher and handlers (1).<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!