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.

Advanced Topics 233<br />

namespace SP<br />

{<br />

enum Mode { Sent, CancelRequested }<br />

enum Status { Cancelled, Completed }<br />

[Feature]<br />

class Cancellation<br />

{<br />

static Map mode = Map.EmptyMap;<br />

[Action("ReqSetup(m,_)")]<br />

[Action("ReqWork(m,_)")]<br />

static void Req(int m) { mode = mode.Add(m, Mode.Sent); }<br />

static bool ReqEnabled(int m) { return !mode.ContainsKey(m); }<br />

[Action]<br />

static void Cancel(int m)<br />

{<br />

if (mode.ContainsKey(m) && mode[m] == Mode.Sent)<br />

mode = mode.Override(m, Mode.CancelRequested);<br />

}<br />

[Action("ResSetup(m,_,s)")]<br />

[Action("ResWork(m,_,s)")]<br />

public static void Res(int m, Status s)<br />

{<br />

mode = mode.RemoveKey(m);<br />

}<br />

public static bool ResEnabled(int m, Status s)<br />

{<br />

return mode.ContainsKey(m) &&<br />

(s != Status.Cancelled || mode[m] == Mode.CancelRequested);<br />

}<br />

[AcceptingStateCondition]<br />

static bool IsAcceptingState() { return mode.IsEmpty; }<br />

}<br />

}<br />

Figure 14.7. Cancellation feature model program.<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!