The only thing you can do is simply modify readStdin so that it can either receive data from real standard input or from a helper function, for example:
char *fakeStdIn = ""; int myfgetc (FILE *fin) { if (*fakeStdIn == '\0') return fgetc (fin); return *fakeStdIn++; } int readStdin(int limit, char *buffer) { char c; int i = 0; int read = FALSE; while ((c = myfgetc(stdin)) != '\n') { if (i <= limit) { *(buffer + i) = c; i++; read = TRUE; } } for (i = i; i < strlen(buffer); i++) { *(buffer + i) = '\0'; } return read; }
Then, to call it from your unit test, you can do:
fakeStdIn = "1\npaxdiablo\nnice guy\n";
By placing the hook on the lower levels, you can enter your own character sequence instead of standard input. And if at some point the fake standard input is exhausted, it returns to the real one.
Obviously this is the use of characters, so if you want to inject EOF events, you will need an array of integers, but this will be a minor modification to the circuit.
source share