I wrote an Android application that (among other things) writes files to disk. Now I wonder what happens when the file system starts from storage . I assume, for example, java.io.FileOutputStream.write() will IOException that I will have to catch.
The fact is that I do not want to rely on my powers as a super ninja - I could forget to try somewhere or not cope with it. So I want to test this scenario .
Unfortunately, I could not find a word about good practice at the same time - even on SO.
Of course, I coldly manually write the file system with something like this, I think:
size = N dir = /some/path data = generateDataForSize(size) while( write(data, dir) ); while( round(size/=2) > 1 ) write(generateDataForSize(size), dir)
Where write() will either generate separate files or add them to one. There may be some problems with generateDataForSize() and large sizes, but let it be delayed for now.
What makes me itchy is that I have to put this in my application and I have to clear this $% #! manually. Well, if I put it in my own directory, I can just drop it all with a single line in the adb shell.
Anyway, is there an easier way to go about this that I am missing? Does the android have any mechanics for this, for example, temporarily limiting the storage space available for each application? Any integrated unit test solutions or sroid tools for Android? How do other people (you) do it?
TL DR : how to use fs effectively to test the case of writing to fs when it is full.
edit: I am testing on a real device that is not deployed. The emulator is slow, even if HAXM is up and running. Unfortunately, using an emulator is not an option.
Tasos Moustakas hints at the limited space available for AVD. I think if you avoid the problems with android:installLocation="preferExternal" and move the application to sd / write files on a limited sd, this is an acceptable solution.
The accepted answer is pretty much what I did. But it still requires some manual work, so feel free to post more answers.