target_alias = @target_alias@
noinst_PROGRAMS = test_muttng
-test_muttng_SOURCES = test_muttng.c
-test_muttng_INCLUDES = @CFLAGS@ test_muttng.h
+test_muttng_SOURCES = test_muttng.c ../lib.c
+test_muttng_INCLUDES = @CFLAGS@ test_muttng.h -I../
test_muttng_LIBS = @LIBS@
subdir = test
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
noinst_PROGRAMS = test_muttng$(EXEEXT)
PROGRAMS = $(noinst_PROGRAMS)
-am_test_muttng_OBJECTS = test_muttng.$(OBJEXT)
+am_test_muttng_OBJECTS = test_muttng.$(OBJEXT) lib.$(OBJEXT)
test_muttng_OBJECTS = $(am_test_muttng_OBJECTS)
test_muttng_LDADD = $(LDADD)
test_muttng_DEPENDENCIES =
.c.obj:
$(COMPILE) -c `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`
+
+lib.o: ../lib.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lib.o `test -f '../lib.c' || echo '$(srcdir)/'`../lib.c
+
+lib.obj: ../lib.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lib.obj `if test -f '../lib.c'; then $(CYGPATH_W) '../lib.c'; else $(CYGPATH_W) '$(srcdir)/../lib.c'; fi`
uninstall-info-am:
ETAGS = etags
/* based on MinUnit */
#include <stdio.h>
+#include <stdlib.h>
#include "test_muttng.h"
+#include <lib.h>
+
int tests_run = 0;
+int asserts_run = 0;
+
+/* XXXXXXXXXXXXXXXXXXXXX */
+/* the following things are only here to satisfy the linker */
+int Umask;
+void (*mutt_error) (const char *, ...);
+const char * gettext(const char * a) { return a; }
+void mutt_exit(int i) { exit(i); }
+/* XXXXXXXXXXXXXXXXXXXX */
+
+
+/* tests the basic functions in lib.c */
+static char * test_lib(void) {
+ /* first check whether allocating 0 bytes behaves correctly */
+ mu_assert("safe_malloc(0)!=NULL",safe_malloc(0)==NULL);
+ mu_assert("safe_calloc(0,0)!=NULL",safe_calloc(0,0)==NULL);
+ mu_assert("safe_calloc(1,0)!=NULL",safe_calloc(1,0)==NULL);
+ mu_assert("safe_calloc(0,1)!=NULL",safe_calloc(0,1)==NULL);
+
+ /* check whether safe_malloc()/safe_free work correctly */
+ {
+ char * ptr;
+ ptr = safe_malloc(1);
+ mu_assert("safe_malloc(1)==NULL",ptr!=NULL);
+ safe_free(&ptr);
+ mu_assert("ptr!=NULL",ptr==NULL);
+ }
+
+ /* check whether safe_strdup works correctly */
+ {
+ char * ptr;
+ mu_assert("safe_strdup(NULL)!=NULL",safe_strdup(NULL)==NULL);
+ mu_assert("safe_strdup("")!=NULL",safe_strdup("")==NULL);
+ ptr = safe_strdup("teststring");
+ mu_assert("safe_strdup(\"teststring\")!=\"teststring\"",strcmp(ptr,"teststring")==0);
+ safe_free(&ptr);
+
+ }
+
+ /* check whether safe_strcat works correctly */
+ {
+ char buf[16] = { 0 };
+ safe_strcat(buf,sizeof(buf),"asdf");
+ mu_assert("buf != \"asdf\"",strcmp(buf,"asdf")==0);
+ safe_strcat(buf,sizeof(buf),"qwer");
+ mu_assert("buf != \"asdfqwer\"",strcmp(buf,"asdfqwer")==0);
+ safe_strcat(buf,sizeof(buf),"0123456789");
+ mu_assert("buf != \"asdfqwer0123456\"",strcmp(buf,"asdfqwer0123456")==0);
+ safe_strcat(buf,sizeof(buf),"trash");
+ mu_assert("buf != \"asdfqwer0123456\" (2)",strcmp(buf,"asdfqwer0123456")==0);
+ }
+
+ /* check whether safe_strncat works correctly */
+ {
+ char buf[16] = { 0 };
+ safe_strncat(buf,sizeof(buf),"asdf",3);
+ mu_assert("buf != \"asd\"",strcmp(buf,"asd")==0);
+ safe_strncat(buf,sizeof(buf),"fghj",3);
+ mu_assert("buf != \"asdfgh\"",strcmp(buf,"asdfgh")==0);
+ safe_strncat(buf,sizeof(buf),"",10);
+ mu_assert("buf != \"asdfgh\" (2)",strcmp(buf,"asdfgh")==0);
+ safe_strncat(buf,sizeof(buf),"qwertzuiopyxcvvbnm",255);
+ mu_assert("buf != \"asdfghqwertzuio\"",strcmp(buf,"asdfghqwertzuio")==0);
+ }
+
+ /* check whether mutt_str_replace works correctly */
+ {
+ char * ptr = NULL;
+ mutt_str_replace(&ptr,"foobar");
+ mu_assert("ptr != \"foobar\"",strcmp(ptr,"foobar")==0);
+ mutt_str_replace(&ptr,"quux");
+ mu_assert("ptr != \"quux\"",strcmp(ptr,"quux")==0);
+ mutt_str_replace(&ptr,NULL);
+ mu_assert("ptr != NULL",ptr==NULL);
+ }
+
+ /* check whether mutt_str_adjust works correctly */
+ {
+ char * ptr = safe_strdup("some teststring");
+ mutt_str_adjust(&ptr);
+ mu_assert("ptr != \"some teststring\"",strcmp(ptr,"some teststring")==0);
+ safe_free(&ptr);
+ }
+
+ /* check whether mutt_strlower works correctly */
+ {
+ char * supposed_result = "all you need is love";
+ char * ptr = safe_strdup("ALL YOU NEED IS LOVE");
+ mu_assert("ptr != \"all you need is love\"",strcmp(mutt_strlower(ptr),supposed_result)==0);
+ mutt_str_replace(&ptr,"All You Need Is LovE");
+ mu_assert("ptr != \"all you need is love\" (2)",strcmp(mutt_strlower(ptr),supposed_result)==0);
+ mutt_str_replace(&ptr,"all you need is love");
+ mu_assert("ptr != \"all you need is love\" (3)",strcmp(mutt_strlower(ptr),supposed_result)==0);
+ safe_free(&ptr);
+ }
-static char * test_case(void) {
- mu_assert("NULL != 0",NULL == 0);
return 0;
}
static char * all_tests(void) {
- mu_run_test(test_case);
+ mu_run_test(test_lib);
return 0;
}
} else {
printf("ALL TESTS PASSED\n");
}
- printf("Tests run: %d\n", tests_run);
+ printf("Tests run: %d\nAssertions checked: %d\n", tests_run,asserts_run);
return result != 0;
}