-
Notifications
You must be signed in to change notification settings - Fork 0
The A1 Harness
This harness run sequentially run over 90 iCalendar test cases in a repository of *.ics
files. It asserts 10 different error codes present in the CIS*2750 project's createCalendar()
function (all except WRITE_ERROR
and OTHER_ERROR
).
It consists entirely of block scopes of the following form:
{
Calendar *calendar;
ICalErrorCode code;
char *error;
char file[] = "TEST/ERROR_CODE/FileName.ics";
code = createCalendar(file, &calendar);
error = printError(code);
if (code == INV_FILE) printf("GOOD: File %s successfully throws %s\n", file, error);
else printf("BAD: File %s collides %s\n", file, error);
if (calendar) printf("Calendar is also not NULLED!\n");
free(error);
}
Users wishing to add their own tests only need to paste another block, change the file
(filename) variable and perhaps the intended ICalErrorCode
, though this step is not needed if you copy and paste a block that already has the intended error code, which is recommended as all tests are run in order of error code.
We walk through the code line-by-line as follows:
Calendar *calendar;
ICalErrorCode code;
char *error;
char file[] = "TEST/ERROR_CODE/FileName.ics";
Here we initialize
- a
Calendar
to store the resultant parsed file in - an
ICalErrorCode
to store the resultant error code in - an
error
string to store the resultant error string - a
char
array to store the filename
code = createCalendar(file, &calendar);
error = printError(code);
Here we attempt to open and parse the iCalendar file and we store the error/result code into code
. Then, using a function that converts the ICalErrorCode
into a human-readable string—printError()
—we dynamically allocate a string and store the error description into error
.
if (code == INV_FILE) printf("GOOD: File %s successfully throws %s\n", file, error);
else printf("BAD: File %s collides %s\n", file, error);
Here is the actual validation part—if the ICalErrorCode
returned by createCalendar()
passes the assertion made previously, a message alerting of such is sent. If not, then we say that there is an error collision and we also send a message alerting of such.
if (calendar) printf("Calendar is also not NULLED!\n");
Here we check if the Calendar
still exists. It is within the assignment specification that we NULL
the Calendar
pointer in the event that an error occurs (presumably for error detection fallback in other functions in the event that the error code falls through).
free(error);
Assuming the program doesn't crash, we free the error string as this will always exist.
During the OK
series of tests, we don't actually check if the Calendar
is NULL
—because no errors occurred during parsing, we expect a non-NULL
Calendar
. So instead, we free the Calendar
as follows:
if (calendar) deleteCalendar(calendar);