+# -*- Makefile -*-
+
CC=gcc
LD=gcc
CFLAGS =-g -Wall `sdl-config --cflags`
-CFLAGS +=-O9 -funroll-loops -fomit-frame-pointer
+#CFLAGS +=-O9 -funroll-loops -fomit-frame-pointer
LDFLAGS=`sdl-config --libs` -lSDL_mixer
C_FILES=src/dlb.c src/linked.c src/sprite.c src/ag.c
src/ag.o: src/ag.c
$(CC) $(CFLAGS) -c -o $@ $^
+src/ag_test.o: src/ag_test.c
+ $(CC) $(CFLAGS) -DUNIT_TEST -c -o $@ $^
+
+tests: test_ag test_linked
+
+test_ag: ag $(TEST_OBJS) src/unittest.h
+ $(LD) $(LDFLAGS) -o $@ $(TEST_OBJS)
+
+test_linked: src/linked.c src/unittest.h
+ $(CC) $(CFLAGS) -Isrc -DUNIT_TEST $< -o $@
+
clean:
rm -f src/*.o
+ rm -f test_linked test_ag
+#ifndef UNIT_TEST
#define UNIT_TEST
+#endif
#include "unittest.h"
+
#define main ag_main
#include "ag.c"
#undef main
static int test_shiftLeftKill()
{
char a[7] = { 'a','b','c','d','e','f', 0 };
- test_equals_str("shiftLeftKill", "bcdef", shiftLeftKill(a));
- test_equals_str("shiftLeftKill const str", "bcdef", shiftLeftKill("abcdef"));
+ char *s = shiftLeftKill(a);
+ test_equals_str("shiftLeftKill", "bcdef", s);
+ free(s);
+ s = shiftLeftKill("abcdef");
+ test_equals_str("shiftLeftKill const str", "bcdef", s);
+ free(s);
return 0;
}
return 0;
}
-static int test_swapChars()
-{
- char a[7] = { 'a','b','c','d','e','f', 0 };
- const char *p = a, *q = NULL;
- test_equals_str("swapChars end", "fbcdea", swapChars(0, 5, a));
- q = swapChars(2, 3, a);
- test_equals_str("swapChars inner", "fbdcea", q);
- test_equals_ptr("swapChars ptr equiv", p, q);
- return 0;
-}
-
-static int test_revFirstNonSpace()
-{
- char a[7] = { 'a','b','c','d','e','f', 0 };
- char b[7] = { 'a','b',SPACE_CHAR,'d','e',SPACE_CHAR, 0 };
- test_equals_int("rev no space", 6, revFirstNonSpace(a));
- test_equals_int("rev find space", 5, revFirstNonSpace(b));
- return 0;
-}
-
static int test_whereinstr()
{
test_equals_int("where is b", 1, whereinstr("abcdef",'b'));
{NULL, test_shiftLeftKill, NULL},
{NULL, test_shiftLeft, NULL},
{NULL, test_nextBlank, NULL},
- {NULL, test_swapChars, NULL},
- {NULL, test_revFirstNonSpace, NULL},
{NULL, test_whereinstr, NULL},
};
int
main(void)
{
- size_t n;
- for (n = 0; n < sizeof(unit_tests)/sizeof(unit_tests[0]); ++n) {
- run_tests(&unit_tests[n]);
- }
- test_print_results();
+ run_tests(unit_tests);
return 0;
}