Repairing a Defect

Unfortunately (or fortunately, depending upon how you look at it), increased code coverage can expose defects.

To fix a defect:

  1. In the Project Browser tab on the right-hand side of the screen, right-click the UmtsCode component testing node and then select View Report->Code Coverage.

  2. Maximize the Code Coverage report. Close the Output Window on the bottom of the UI

  3. View the code_int code in the Source window of the Code Coverage viewer (using the Report tab, and then look at the while statement for which you have been trying to improve code coverage.

The while statement is green, which means it is now fully covered (left-click it if you wish to be sure). Should you check the component testing report? Is it safe to assume that no defect has been uncovered by your effort to increase coverage?

  1. In the Project Browser tab on the right-hand side of the screen, right-click the UmtsCode component testing node and then select View Report->Test

A failure is reported in the component testing report, so the effort to improve coverage has resulted in the discovery of a new defect. The Report Window on the left-hand side of the screen flags this error nicely.

  1. In the Report Window, select the Element1 node that has a Failed symbol to its left.

Given x equal to 0, the code_int function is supposed to assign buffer a value of I10. However, this did not happen. buffer has a value of I0 - a defect.

  1. Select the Code Coverage tab.

  2. Hover the mouse over the while statement for which you have been trying to improve coverage, then right-click and select Edit Source.

If you continue to read this section, you will be told what is wrong and how to fix the problem. Feeling adventurous? Don't read on and see if you can solve the problem yourself.

When you're ready, just go to the next section in Exercise Three entitled Verifying the Success of Your Repairs.

The problem is that because the while statement never handles x with a value of 0:

So a buffer value of I0 reflects a length of 0 and an absence of the value of x. You need to take care of the special case in which x equals 0.

  1. Immediately before the while statement for which you have been attempting to improve coverage, add the following line:

if (x==0) {*ptr='0';len++;ptr++;}

  1. From the File menu, select Save.

This should fix the problem.