I've written a C code which takes a path to a directory and a string s. After opening the directory, the code looks for files with a particular extension and write the string given as a second argument to the last line of these files and a \n after it. This is all my function does (finding files with a particular extension and writing something at the end of the file). The C code for the function is done but I need to write some tests for the function using Cunit and I don't have any Idea how to write them. I've just written down what I want to test (below) but I don't know how to write them using Cunit. Can anyone help me with that? Thanks
- check if the user checks if the string 's' is nULL => segmentation fault
- check if bad address is given to the path argument of the function when there is no ".extension" file
- check if strcmp compares ".extension" and not "extension"
- check if the user uses == instead of strcmp to compare the extension
- check if the string 's' is written on a new line
- check the size of the string 's' sent to write => sent without \0 by strlen and the type is size_t
- check if the file is opened for writing (and not read only)
- check if string 's' is converted to void* before giving it to write function
- check if the return value of open ("fd") is checked
- check if the return value of opening a directory is checked (null or not)
- check if the return value of reading a directory is checked (null or not)
- check if the extension is checked (the string 's' is not added to all the files with other extensions
- check if the function ignores the '.' et '..' directories => DT_REG
- check if the file is closed after being opened
- check the return value of close
- check if the directory is closed after being opened
- check the return value of the directory