My piece of code which I am doing unit testing on is something like this:
if(((State !=TCPIP_IPADDR_STATE_ASSIGNED)&& (State !=TCPIP_IPADDR_STATE_ONHOLD) && (State !=TCPIP_IPADDR_STATE_UNASSIGNED)) ||(SoConId==DOIP_INVALID_16))
{
}
And my unit test case includes following:
`DoIP_LocalIpAddrAssignmentChg(12,0xFF);`
Where DoIP_LocalIpAddrAssignmentChg is the function name in which if is located and 0xFF is for invalid state which is obviously not equal to all 3: TCPIP_IPADDR_STATE_ASSIGNED , TCPIP_IPADDR_STATE_ONHOLD , TCPIP_IPADDR_STATE_UNASSIGNED . The value of SoConId is 12 . The value of DOIP_INVALID_16 = 0xFF .
So when I check my unit test report, its gives this result: My question is why it's not covering condition for TCPIP_IPADDR_STATE_UNASSIGNED as value for state I am passing is 0xFF which is invalid value.
You're a "victim" of lazy evaluation.
Chapter 6.5.14 "Logical OR opeartor":
If the first operand compares unequal to 0, the second operand is not evaluated.
All three parts of the multiple-AND are true
, and so unequal to 0.
Both logical &&
are covered, but you can't see it because of the ||
in the same line not being fully executed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.