In this appendix, an example is used for illustrating the test coverage analysis metrics of Panorama C/C++.
SUM_PRODUCT is a sample program which requests the input of three integers: Low, High and Max. The integers should not be negative, otherwise an error message will be given. When SUM_PRODUCT receives three integers, it outputs for each number k in the
The source code of SUM_PRODUCT.cc is listed below:
The Makefile of SUM_PRODUCT is listed below:
A SUM_PRODUCT.hsi file is generated from the Makefile of SUM_PRODUCT and loaded into the Main Menu of Panorama C/C++. Then, a .dbs file is created for SUM_PRODUCT. To capture the dynamic test coverage data, SUM_PRODUCT is executed with several groups of integers as listed below:
LOW | HIGH | MAX |
---|---|---|
A series of bar graphs in OO-Test, J-Flow and J-Diagrams in OO-Diagrammer are listed to show the changes of accumulated test coverage each time when SUM_PRODUCT is executed.
Note: In this Appendix, the test coverage refers to the Accumulated test coverage in order to show the result of all the executions.
Before the execution of SUM_PRODUCT, the test coverage of the code is zero. This is reflected in the bar graph and diagrams below:
To execute the sample program, type SUM_PRODUCT under appropriate directory at prompt:
Enter positive integers LOW, HIGH, and MAX: 2 8 0
The bold characters above are typed in at the prompts, while the italic characters are displayed by the sample program SUM_PRODUCT.
Then check the Bar graphs in OO-Test, J-Flow and J-Diagram in OO-Diagrammer. Select the Accumulated test coverage on the corresponding Options dialog box, then click OK. The test coverage data are automatically updated:
The test coverage data show, after the first execution of SUM_PRODUCT, that the test coverage of Function and Condition True have been 100 percent.
Now, execute SUM_PRODUCT again. This time three integers 10, 20, and 12 are inputted. SUM_PRODUCT outputs, from 10 to 20, 11 groups of equations:
Enter positive integers LOW, HIGH, and MAX:10 20 12
The bold characters above are typed in at the prompts, while the italic characters are displayed by the sample program SUM_PRODUCT.
Then check the Bar graphs in OO-Test, J-Flow and J-Diagram in OO-Diagrammer. Select the Accumulated Test Coverage Data on the corresponding Options dialog box, then click OK. The test coverage data on the diagrams are automatically updated:
Accumulated test coverage:
Function and Condition True remains 100% covered. Other test metrics data have increased significantly.
Accumulated test coverage: the numbers of untested elements have decreased after hte second execution of SUM_PRODUCT.
Accumulated Test Coverage: The number of unexecuted elements highlighted has been greatly decresed compared to the diagrams before.
Now, execute SUM_PRODUCT again to increase its test coverage furthermore. This time integers 10, 1, 11 are inputted.
Enter positive integers LOW, HIGH, and MAX:10 1 11
The bold characters above are typed in at the prompts, while the italic characters are displayed by the sample program SUM_PRODUCT.
Since Low=10 > High=1, no equation is outputted this time.
Then check the Bar graphs in OO-Test, J-Flow and J-Diagram in OO-Diagrammer. Select the Accumulated Test Coverage on the corresponding Options dialog box, then click OK. The test coverage data are automatically updated:
Accumulated Test Coverage: Compared to Figure A-9, one more branch and one more segment are tested. Consequently, J-Coverage is increased by one too.
Accumulated Test Coverage: The number of untested elements is further decreased.
Accumulated test coverage: Compared to Figure A-11, one more segment (branch) is tested.
Accumulated Test Coverage: Compared to Figure A-12, one more segment (branch) is tested.
Now, carefully observe the J-Flow or J-Diagram, you may find out that the condition test coverage should be increased. Since Condition True has reached 100% coverage, the Condition False needs to be increased.
Enter positive integers LOW, HIGH, and MAX:2 8 -2
Error! The input data are incorrect!
The bold characters above are typed in at the prompts, while the italic characters are displayed by the sample program SUM_PRODUCT.
Since a negative integer is inputted, an error message is given this time.
Then check the Bar graphs in OO-Test, J-Flow and J-Diagram in OO-Diagrammer. Select the Accumulated test coverage on the corresponding Options dialog box, then click OK. The test coverage data are automatically updated:
The accumulated test coverage data of Branch, SC0, SC1 and SC1+ have reached 100%. The Condition False, Condition Both and J-Coverage have been increased too.
Accumulatively, only 2 elements in Condition False or in Condition Both or in J-Coverage are untested.
To increase the coverage of Condition False, run SUM_PRODUCT again and input another group of integers. This time, integer High is negative.
Enter positive integers LOW, HIGH, and MAX:2 -2 8
Error! The input data are incorrect!
The bold characters above are typed in at the prompts, while the italic characters are displayed by the sample program SUM_PRODUCT.
Since negative integer High is inputted, an error message is given too.
Then check the Bar graphs in OO-Test, J-Flow and J-Diagram in OO-Diagrammer. Select the Accumulated test coverage in the corresponding Options dialog box, then click OK. The test coverage data are automatically updated:
To cover all the conditions, run SUM_PRODUCT again and input another group of data with negative Low integer.
Enter positive integers LOW, HIGH, and MAX:-2 2 8
Error! The input data are incorrect!
The bold characters above are typed in at the prompts, while the italic characters are displayed by the sample program SUM_PRODUCT.
Since negative integer Low is inputted, an error message is given too.
Then check the Bar graphs in OO-Test, J-Flow and J-Diagram in OO-Diagrammer. Select the Accumulated test coverage on the corresponding Options dialog box, then click OK. All the conditions should have been covered:
The sample program SUM_PRODUCT is completly tested.
The sample program SUM_PRODUCT is completly tested.
From the example above, it is clearly shown how test coverage data are displayed on J-Flows and J-Diagrams, and how the result shown may help you to increase the coverage of your program.
Similarly, other tools of Panorama C/C++, such as the structure charts, software metrics diagrams, reports, ActionPlus diagrams, etc., can also show the dynamic test data vividly and help you successfully plan the further testing.