End of function coverage after switch case
-
Hi there, my organization is currently attempting to integrate coco into our development for code coverage. We're attempting to do mc/dc coverage on some code of ours and ran into a bit of a snag.
Here is the coveragescanner results of some of the code:
Our concern is that we need to show that we are able to hit each function entrance and exit (if possible), and in this case after breaking out of the switch statement the reports do not indicate that the end of the function was hit.
Testing without the final break in the default case of the switch statement does hit the end of the function:
Here are some further examples we ran into playing around with the code:
Removing the break on the default statement reached the end of the function as did adding a line of code after the switch statement.
I was wondering if anybody ran into any kind of a similar issue and might know what is going on here?
Thank you
-
I don't fully understand what the question is, and how it relates to Qt.
Our concern is that we need to show that we are able to hit each function entrance and exit (if possible), and in this case after breaking out of the switch statement the reports do not indicate that the end of the function was hit.
All examples shown always reach the end of the function, simply because there is no return in the
switch
.
Adding adefault
handler doesn't change that, neither does adding abreak
to the default section.The
break
simply means, that there is no "fallthrough" to the nextcase
.switch (a) { case 0: // do something only if a == 0 case 1: // do something if a == 0 or a == 1 break; case 2: // do something only if a == 2 break; default: // do something in all other cases break; // technically not necessary, but good practice anyway. } qDebug() << "end of function reached";
-
@Axel-Spoerl
I think the problem is that OP is using some tool to analyze code coverageHere is the coveragescanner results of
While it is true that all the code blocks he shows are "good", for whatever reason his "coveragescanner" tool does not report that the end of the function is reached in certain cases where
default
/break
are/are not used.As you say, however, this does not relate to Qt and seems to be an issue OP needs to take up with code coverage tool or find a workaround which keeps it happy.
-
Q_UNREACHABLE()
andQ_UNREACHABLE_RETURN(x)
- another pair of magic macros, working wonders ;-) -
This post is deleted!
-
This post is deleted!