views:

53

answers:

2

Using VS2008, we would like to simulate a file that has a size of X, but that has a read failure at X-Y bytes, so that we get an error indication.

Anyone have an idea of how to do this on windows? Looks like there is a solution for linux, but I can't really come up with a way to do this on windows. We have multiple developers, multiple machines, and cppunit testing framework, so I want a software only design.

I'm trying to simulate the actual CRT failing, so I can test the code that is dealing with the failure.

+4  A: 

Wrap the file I/O functions in a class; override those in a testing derived class; simulate failure with a fake or mock.

Billy ONeal
A: 

I'm not sure if this would work, but you could try creating a file and then truncating it at x-y bytes, creating a new file w/header at that location. I don't know how you would do that, though. Another idea is to open the file, seek to the byte before, then change the permissions so you can no longer read the file - though if there's a file lock in place you'd have to get around that.

I'm not super familiar with the Windows File systems though, so these are just guesses.

Wayne Werner