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.

22 <strong>Why</strong> <strong>We</strong> <strong>Need</strong> <strong>Model</strong>-<strong>Based</strong> <strong>Testing</strong><br />

using System;<br />

using System.Net; // Dns and IPHostEntry<br />

namespace ClientServerImpl<br />

{<br />

// Remote instrument standalone client program, works with Monitor server.<br />

}<br />

class Logger<br />

{<br />

#region usage method, writes help text (code not shown)<br />

}<br />

static void Main(string[] args)<br />

{<br />

string host = "127.0.0.1";<br />

int port = 8000;<br />

int nsamples = Int32.MaxValue; // unlimited, in effect<br />

int interval = 1;<br />

string command = "T"; // get temperature sample<br />

string units = "F";<br />

}<br />

double temperature;<br />

IPHostEntry iphe; // for checking host address string<br />

#region Check and process command line arguments (code not shown)<br />

Client client = new Client();<br />

client.Socket();<br />

client.Connect(host,port);<br />

for (int i = 0; i < nsamples; i++)<br />

{<br />

client.Send(command);<br />

temperature = client.Receive();<br />

if (units == "C")<br />

temperature = Temperature.ConvertToCelsius(temperature);<br />

Console.WriteLine("{0:u} Temperature server at {1} " +<br />

"port {2} reports {3,5:F1} {4}",<br />

DateTime.Now, host, port, temperature,units);<br />

client.Sleep(interval);<br />

}<br />

client.Close();<br />

Figure 2.8. Temperature logger, a client application.<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!