01.02.2013 Views

Software Development Cross Solution - Index of - Free

Software Development Cross Solution - Index of - Free

Software Development Cross Solution - Index of - Free

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.

tested code is completed code<br />

}<br />

258 Chapter 7<br />

Here’s the code we changed in Chapter 6. The bug has to be related to this stuff somewhere.<br />

Find the bug that bit us this time.<br />

public void buildGUI() {<br />

// code from buildGUI<br />

JButton sendIt = new JButton(“sendIt”);<br />

sendIt.addActionListener(new MySendListener());<br />

buttonBox.add(sendIt);<br />

JButton sendPoke = new JButton(“Send Poke”);<br />

sendPoke.addActionListener(new MyPokeListener());<br />

buttonBox.add(sendPoke);<br />

userMessage = new JTextField();<br />

buttonBox.add(userMessage);<br />

// more code in buildGUI()<br />

}<br />

public class MyPokeListener implements ActionListener {<br />

public void actionPerformed(ActionEvent a) {<br />

// We’ll create an empty state array here<br />

boolean[] checkboxState = new boolean[255];<br />

try {<br />

out.writeObject(POKE_START_SEQUENCE);<br />

out.writeObject(checkboxState);<br />

} catch (Exception ex) {<br />

System.out.println(“Failed to poke!”); }<br />

}<br />

}<br />

// other code in BeatBoxFinal.java<br />

What went wrong in this code?<br />

Why didn’t our tests catch this?<br />

What would you do differently?<br />

When we send the dummy array <strong>of</strong> checkboxes, we’re <strong>of</strong>f by one-we only send<br />

255 checkboxes, and it should be 256 (16x16).<br />

Our tests sent valid arrays to our receiver code, but we didn’t really test<br />

the GUI side <strong>of</strong> the application.<br />

We need a way to test more <strong>of</strong> our code. We should add a test that will<br />

catch this. (But what else are we missing?)<br />

Download at WoweBook.Com<br />

Here’s the bug.<br />

We create an<br />

array <strong>of</strong> 255<br />

booleans instead<br />

<strong>of</strong> 256.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!