diff --git a/src/fakeinput.h b/src/fakeinput.h new file mode 100644 index 0000000..0438f60 --- /dev/null +++ b/src/fakeinput.h @@ -0,0 +1,6 @@ +// fakeinput.h exists solely for testing purposes +// fakeInput is set by unit tests to inject specific inputs for testing +#ifndef FAKEINPUT_H +#define FAKEINPUT_H +extern char **fakeInput; +#endif \ No newline at end of file diff --git a/src/userinput.c b/src/userinput.c index cdf03c6..3211732 100644 --- a/src/userinput.c +++ b/src/userinput.c @@ -1,4 +1,5 @@ #include "userinput.h" +#include "fakeinput.h" #include #include @@ -9,6 +10,8 @@ #include #include +char **fakeInput = NULL; + #define LD(name)\ long double name##ldvalue;\ long double *name##ld = NULL;\ @@ -39,6 +42,16 @@ void trimRight(char *input) { } char *readInput() { + if (fakeInput != NULL) { + if (fakeInput[0] == NULL) { + printf("The given list of inputs in the test was exceeded!\n"); + exit(1); + } + char *result = malloc(strlen(fakeInput[0])*sizeof(char) + 1); + strcpy(result, fakeInput[0]); + fakeInput = fakeInput + 1; + return result; + } size_t bufferSize = 100; char *buffer = malloc(bufferSize*sizeof(char)); char c;