#include #include #include #include #include #include "StrFns.h" void testStrLength(FILE *Log); void testStrCopy(FILE *Log); FILE *Log; #define FOR_LINUX #ifdef FOR_LINUX void segfaultHandler(int sig) { fprintf(Log, "Oops... the system sent a SIGSEGV to this process.\n"); fprintf(Log, "You must have created a bad pointer!\n"); exit(1); } #endif int main(int argc, char** argv) { #ifdef FOR_LINUX signal(SIGSEGV, segfaultHandler); #endif Log = fopen("Log.txt", "w"); fprintf(Log, "Test program for C string function implementations.\n"); fprintf(Log, "Beginning test of strlength() implementation.\n"); testStrLength(Log); fprintf(Log, "Completed test of strlength() implementation.\n"); fprintf(Log, "\n"); fprintf(Log, "Beginning test of strcopy() implementation.\n"); testStrCopy(Log); fprintf(Log, "Completed test of strcopy() implementation.\n"); fclose(Log); return 0; } void testStrLength(FILE *Log) { char* s = "Try different strings here."; // test string uint32_t Length = strlen(s); // use Standard Lib fn as check fprintf(Log, "Test string of length %u: %s\n", Length, s); unsigned int reportedLength = stringlength(s); fprintf(Log, "Reported length is:\n"); fprintf(Log, "%u\n", reportedLength); } void testStrCopy(FILE *Log) { char* s = "Try different strings here."; // test string uint32_t Length = strlen(s); // use Standard Lib fn to get length char* t = NULL; // pointer for copy fprintf(Log, "Test string: %s\n", s); t = stringcopy(s); fprintf(Log, "Copy made was:\n"); fprintf(Log, "%s\n", t); free(t); // dealloc space for copy }