I have a C application. Which creates a connection to file at startup and it continuously runs for many days.
I am only connecting one time . and not reconnecting it in code. Only checking if
if(NULL == file)
Is there can be case that my application lose I/O connection of that file handler ?
if yes. Is there a way , How can I create test case for it ?
Yes it's possible. For example if the file is on another machine or on a removable storage. Then you can physically disconnect/unplug the device and the subsequent operations on the handle will fail.
As others mentioned in the comments, you can simulate it in a test case by creating a RAM disk and either unmounting it or killing the driver. Alternatively, if all you care is about unidirectional I/O, maybe you could test your code with a pipe, and then close the other end of the pipe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With