Apr 17, 2018 at 5:25am
Can you post the code for msg_error_when?
Apr 17, 2018 at 8:23am
In test mode, you could have TEST_MODE defined. Either in the code, or as an argument passed to the compiler.
Then something like this in the right place:
1 2 3
|
#ifdef TEST_MODE
#define fopen(x, y) nullptr;
#endif
| |
which would turn your fopen call into a straight nullptr value.
I've not tested this and I rarely use this kind of preprocessor macro, so it might be bad syntax; the idea should be solid.
Even something as awkward as
1 2 3 4 5
|
#ifdef TEST_MODE_FAIL_FILE_OPEN
FILE *f = nullptr;
#else
FILE *f = fopen(filename.c_str(), "r");
#endif
| |
at line 8 would do it, although it's possible to end up getting silly with excessive preprocessor magic.
Last edited on Apr 17, 2018 at 8:26am
Apr 17, 2018 at 8:08pm
Change the permissions on the file so it can't be read by the program.