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.

80 <strong>Model</strong> Programs<br />

}<br />

}<br />

// ... continued<br />

public static bool ClientReceiveEnabled()<br />

{<br />

return (clientSocket == Socket.Connected<br />

&& phase == Phase.ClientReceive);<br />

}<br />

// Return value needed here, server sends different values<br />

[Action]<br />

public static double ClientReceive()<br />

{<br />

double t = clientBuffer;<br />

clientBuffer = EmptyBuffer;<br />

phase = Phase.Send;<br />

return t;<br />

}<br />

public static bool ClientCloseEnabled()<br />

{<br />

return (clientSocket == Socket.Created<br />

|| clientSocket == Socket.Connected);<br />

}<br />

[Action] public static void ClientClose()<br />

{<br />

clientSocket = Socket.Closed;<br />

}<br />

Figure 5.11. Remote instrument client/server: model program (part 5).<br />

all the action method names must be different (you cannot use the class names to<br />

distinguish them).<br />

The Socket type enumerates the values of the two control state variables server-<br />

Socket and clientSocket. They represent the steps in the protocol shown in Chapter<br />

2, Figure 2.2. The Socket type provides all of the values needed by both sockets,<br />

although each socket uses only some of them. Both variables are initialized to None<br />

to indicate no sockets have been allocated, and are intended to reach Closed at the<br />

end of every run.<br />

The Phase type enumerates the values of the control state variable phase. They<br />

represent the alternation of send and receive actions. The initialization ensures that<br />

a send action comes first. The phase variable is updated by the send and receive<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!