diff --git a/src/GNUmakefile.common b/src/GNUmakefile.common index a040b8f..700fd57 100644 --- a/src/GNUmakefile.common +++ b/src/GNUmakefile.common @@ -11,6 +11,7 @@ ODOORS:= ${DEPSDIR}/odoors/libs-${OS}/libODoors.a JSMN:= ${DEPSDIR}/jsmn/libjsmn.a CDK:= ${DEPSDIR}/cdk-5-20161210/libcdk.a UUID:= ${DEPSDIR}/libuuid/.libs/libuuid.a +CUTEST:= ${DEPSDIR}/cutest-1.5/libcutest.a all: magicka magimail magiedit ticproc mgpost magichat \ filecenter dosbox_shim magiftpd reset_pass @@ -46,6 +47,9 @@ ${UUID}: cd ${DEPSDIR}/libuuid/ && ./configure cd ${DEPSDIR}/libuuid/ && ${MAKE} CC=${CC} +${CUTEST}: + cd ${DEPSDIR}/cutest-1.5 && make + HDRS:= bbs.h OBJS:= inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o \ doors.o bbs_list.o chat_system.o email.o files.o settings.o \ @@ -63,7 +67,7 @@ endif %.o: %.c ${HDRS} ${CC} -c -o $@ $< ${CFLAGS} -magickawww: ${OBJS} ${WWWOBJS} ${LUA} ${ZMODEM} ${B64} ${JAMLIB} ${JSMN} ${UUID} +magickawww: ${OBJS} ${WWWOBJS} ${LUA} ${ZMODEM} ${B64} ${JAMLIB} ${JSMN} ${UUID} ${CC} -o ../magicka $^ ${LIBS} -lmicrohttpd magicka: ${OBJS} ${LUA} ${ZMODEM} ${JAMLIB} ${JSMN} ${UUID} @@ -116,3 +120,5 @@ clean: cd ${UTILSDIR}/magiftpd && ${MAKE} clean cd ${UTILSDIR}/reset_pass && ${MAKE} clean cd ${UTILSDIR}/dosbox_shim && ${MAKE} clean + cd ${DEPSDIR}/libuuid && ${MAKE} clean + cd ${DEPSDIR}/cutest-1.5 && ${MAKE} clean diff --git a/src/stralloc/stralloc.c b/src/stralloc/stralloc.c index 10473ed..fcd6cd4 100644 --- a/src/stralloc/stralloc.c +++ b/src/stralloc/stralloc.c @@ -33,7 +33,7 @@ int stralloc_starts(stralloc *sa, const char *s) { assert(sa != NULL); assert(s != NULL); len = strlen(s); - return (sa->len >= len) && memcmp(sa->s, s, len); + return (sa->len >= len) && memcmp(sa->s, s, len) == 0; } int stralloc_copyb(stralloc *sa, const char *s, size_t n) { diff --git a/src/stralloc/test_stralloc.c b/src/stralloc/test_stralloc.c new file mode 100644 index 0000000..87be9d9 --- /dev/null +++ b/src/stralloc/test_stralloc.c @@ -0,0 +1,58 @@ +#include +#include +#include + +#include "CuTest.h" + +#include "stralloc.h" + +void test_stralloc_starts(CuTest* tc) { + stralloc sa = EMPTY_STRALLOC; + stralloc_copys(&sa, "This is a test"); + CuAssertTrue(tc, stralloc_starts(&sa, "This")); +} + +void test_stralloc_starts_equal(CuTest* tc) { + stralloc sa = EMPTY_STRALLOC; + stralloc_copys(&sa, "This is a test"); + CuAssertTrue(tc, stralloc_starts(&sa, "This is a test")); +} + +void test_stralloc_starts_notequal(CuTest* tc) { + stralloc sa = EMPTY_STRALLOC; + stralloc_copys(&sa, "This is a test"); + CuAssertTrue(tc, !stralloc_starts(&sa, "this")); +} + +void test_stralloc_starts_toolong(CuTest* tc) { + stralloc sa = EMPTY_STRALLOC; + stralloc_copys(&sa, "This is a test"); + CuAssertTrue(tc, !stralloc_starts(&sa, "This is a test!")); +} + +CuSuite* stralloc_suite(void) { + CuSuite* suite = CuSuiteNew(); + + SUITE_ADD_TEST(suite, test_stralloc_starts); + SUITE_ADD_TEST(suite, test_stralloc_starts_equal); + SUITE_ADD_TEST(suite, test_stralloc_starts_notequal); + SUITE_ADD_TEST(suite, test_stralloc_starts_toolong); + + return suite; +} + +void RunAllTests(void) { + CuString *output = CuStringNew(); + CuSuite* suite = CuSuiteNew(); + + CuSuiteAddSuite(suite, stralloc_suite()); + + CuSuiteRun(suite); + CuSuiteSummary(suite, output); + CuSuiteDetails(suite, output); + printf("%s\n", output->buffer); +} + +int main(void) { + RunAllTests(); +}