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.

}<br />

}<br />

Overview 37<br />

// ... continued<br />

bool CheckMessageEnabled()<br />

{<br />

return (cevent == ControlEvent.Message && waitfor == WaitFor.Message);<br />

}<br />

void CheckMessage()<br />

{<br />

double tol = 5.0;<br />

Console.Write(" CheckMessage ’{0}’", buffer);<br />

try {<br />

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

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

Console.Write(", compare to {0}", previous);<br />

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

previous = data;<br />

sensor = Sensor.OK;<br />

}<br />

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

Console.WriteLine(", {0}", sensor);<br />

}<br />

catch {<br />

sensor = Sensor.Error;<br />

Console.WriteLine(", Error");<br />

}<br />

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

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

waitfor = WaitFor.Timeout;<br />

}<br />

bool ReportLostMessageEnabled()<br />

{<br />

return (cevent == ControlEvent.Timeout && waitfor == WaitFor.Message<br />

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

}<br />

void ReportLostMessage()<br />

{<br />

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

// sensor = Sensor.Error; NOT! Doesn’t change sensor<br />

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

waitfor = WaitFor.Timeout;<br />

}<br />

void PollSensor() {}<br />

void ResetSensor() {}<br />

void CancelTimer() { timer.Enabled = false; }<br />

void StartTimer(int interval) {<br />

timer.Interval = interval; timer.Enabled = true;<br />

}<br />

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