Handling errno in unit tests
Comments
-
My stub:
int errno; (I have also tried this as an extern with the same result)
int errnoVal = 0;
float expVal = 0.0;
void CppTest_StubCallback_exp_sigmoid(CppTest_StubCallInfo* stubCallInfo, float *__return, float *x )
{
*__return = expVal;
errno = errnoVal;
}0 -
Figured it out. Looked in errno.h. The definition of errno is:
_CRTIMP __cdecl __MINGW_NOTHROW int *_errno(void);define errno (*_errno())
This means I needed to do this as a stub:
int errnoVal = 0;
int errnoLoad = 0;
void CppTest_StubCallback_errno(CppTest_StubCallInfo *stubCallInfo, int **__return)
{
*__return = &errnoVal;
}Put in stub function to set errno: errnoVal = errnoLoad;
and implement in the actual test:
errnoVal = 0; // clear errrno
errnoLoad = 100;
CPPTEST_REGISTER_STUB_CALLBACK("_errno", &CppTest_StubCallback_errno);0