From 6ba441d9aa9e15b509647ca854ae2bf43d045ed8 Mon Sep 17 00:00:00 2001 From: Andreas Waidler Date: Sat, 23 Apr 2011 22:30:44 +0200 Subject: [PATCH] Organized directory structure. --- .gitignore | 2 +- Make.config | 9 ++- Makefile | 71 ++++++----------- TODO | 4 +- src/Makefile | 23 ++++++ agg.c => src/agg.c | 0 bool.h => src/bool.h | 0 config.h => src/config.h | 0 expat.c => src/expat.c | 0 expat.h => src/expat.h | 0 fail.c => src/fail.c | 0 fail.h => src/fail.h | 0 fs.c => src/fs.c | 5 ++ fs.h => src/fs.h | 2 + layer.c => src/layer.c | 0 layer.h => src/layer.h | 0 nomtime => src/nomtime | 0 rss.c => src/rss.c | 0 rss.h => src/rss.h | 0 stack.c => src/stack.c | 0 stack.h => src/stack.h | 0 text.c => src/text.c | 0 text.h => src/text.h | 0 tests_dev/Makefile | 20 +++++ tests_dev.c => tests_dev/tests.c | 91 ++++++++++++++++------ tests_usr/Makefile | 8 ++ tests_titlelate.rss => tests_usr/late_title.rss | 0 tests_long.rss => tests_usr/long.rss | 0 tests_titleless.rss => tests_usr/no_title.rss | 0 tests.rss => tests_usr/sample.rss | 0 .../simple_d.rss | 0 tests_simple_titles.rss => tests_usr/simple_t.rss | 0 tests_usr.sh => tests_usr/tests | 32 ++++---- 33 files changed, 174 insertions(+), 93 deletions(-) rewrite Makefile (88%) create mode 100644 src/Makefile rename agg.c => src/agg.c (100%) rename bool.h => src/bool.h (100%) rename config.h => src/config.h (100%) rename expat.c => src/expat.c (100%) rename expat.h => src/expat.h (100%) rename fail.c => src/fail.c (100%) rename fail.h => src/fail.h (100%) rename fs.c => src/fs.c (98%) rename fs.h => src/fs.h (97%) rename layer.c => src/layer.c (100%) rename layer.h => src/layer.h (100%) rename nomtime => src/nomtime (100%) rename rss.c => src/rss.c (100%) rename rss.h => src/rss.h (100%) rename stack.c => src/stack.c (100%) rename stack.h => src/stack.h (100%) rename text.c => src/text.c (100%) rename text.h => src/text.h (100%) create mode 100644 tests_dev/Makefile rename tests_dev.c => tests_dev/tests.c (69%) create mode 100644 tests_usr/Makefile rename tests_titlelate.rss => tests_usr/late_title.rss (100%) rename tests_long.rss => tests_usr/long.rss (100%) rename tests_titleless.rss => tests_usr/no_title.rss (100%) rename tests.rss => tests_usr/sample.rss (100%) rename tests_simple_descriptions.rss => tests_usr/simple_d.rss (100%) rename tests_simple_titles.rss => tests_usr/simple_t.rss (100%) rename tests_usr.sh => tests_usr/tests (91%) diff --git a/.gitignore b/.gitignore index d0c41c0..981d4e2 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,4 @@ *.LOCAL.* *.REMOTE.* agg -tests_dev +tests_dev/tests diff --git a/Make.config b/Make.config index 4933de0..f899696 100644 --- a/Make.config +++ b/Make.config @@ -1,2 +1,7 @@ -#PREFIX = /usr/local -#MANDIR = $(PREFIX)/man +PREFIX = /usr/local +MANDIR = $(PREFIX)/man + +# You hopefully won't have to touch the following lines. +CFLAGS = -W -Wall -Werror -Wfatal-errors -Wextra +CFLAGS += -pedantic-errors +CFLAGS += -std=c89 diff --git a/Makefile b/Makefile dissimilarity index 88% index 9d9c136..1f46027 100644 --- a/Makefile +++ b/Makefile @@ -1,49 +1,22 @@ --include Make.config - -PREFIX ?= /usr/local -MANDIR ?= $(PREFIX)/man - -INST ?= install -RM ?= rm -CC ?= gcc - -CFLAGS=-W -Wall -Werror -Wfatal-errors -Wextra -pedantic-errors -std=c89 -LDFLAGS=-lexpat -LIBS=expat.o fail.o rss.o stack.o text.o layer.o fs.o -POBJ=agg.o -POUT=agg -TOBJ=tests_dev.o -TOUT=tests_dev -TUSR=tests_usr.sh -MAN=agg.1 - -all: $(POUT) -tests: run_tests_dev run_tests_usr - -install: all - $(INST) -m 555 -s $(POUT) $(PREFIX)/bin - $(INST) -m 555 nomtime $(PREFIX)/bin - $(INST) -m 444 $(MAN) $(MANDIR)/man1 - -uninstall: - $(RM) $(PREFIX)/bin/$(POUT) - $(RM) $(PREFIX)/bin/nomtime - $(RM) $(MANDIR)/man1/$(MAN) - -run_tests_dev: $(TOUT) - ./$(TOUT) - -run_tests_usr: $(POUT) - ./$(TUSR) - -$(POUT): $(LIBS) $(POBJ) - $(CC) $(LDFLAGS) $(LIBS) $(POBJ) -o $(POUT) - -$(TOUT): $(LIBS) $(TOBJ) - $(CC) $(LDFLAGS) $(LIBS) $(TOBJ) -o $(TOUT) - -clean: - $(RM) -f $(LIBS) $(POBJ) $(POUT) $(TOBJ) $(TOUT) - -%.o: %.c - $(CC) $(CFLAGS) -c $< +-include Make.config + +MAN=agg.1 + +all: + make -C src + +tests: all + make -C tests_dev run + make -C tests_usr run + +install: all + make -C src install + make -C bin install + $(INST) -m 444 $(MAN) $(MANDIR)/man1 + +uninstall: + make -C src uninstall + +clean: + make -C src clean + make -C tests_dev clean diff --git a/TODO b/TODO index 6dc4088..a3e6e16 100644 --- a/TODO +++ b/TODO @@ -1,10 +1,8 @@ * QA + * fail if item title is not called at first * test for buffer overflows when reading from global buffer into special ones (item, etc). * test whether nomtime can handle complicated filenames - * split into subdirectories - * split acceptance test into seperate dir, - tests into seperate files * test driven refactoring * more assertions * replace assertions by proper error handling diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..738c5b3 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,23 @@ +-include ../Make.config + +LDFLAGS=-lexpat +LIBS=expat.o fail.o rss.o stack.o text.o layer.o fs.o +POBJ=agg.o +POUT=agg +NOMT=nomtime + +all: $(POUT) +tests: $(LIBS) + +$(POUT): $(LIBS) $(POBJ) + $(CC) $(LDFLAGS) $(LIBS) $(POBJ) -o $(POUT) + +install: all + $(INST) -m 555 -s $(POUT) $(PREFIX)/bin + $(INST) -m 555 -s $(NOMT) $(PREFIX)/bin + +clean: + $(RM) -f $(LIBS) $(POBJ) $(POUT) + +%.o: %.c + $(CC) $(CFLAGS) -c $< diff --git a/agg.c b/src/agg.c similarity index 100% rename from agg.c rename to src/agg.c diff --git a/bool.h b/src/bool.h similarity index 100% rename from bool.h rename to src/bool.h diff --git a/config.h b/src/config.h similarity index 100% rename from config.h rename to src/config.h diff --git a/expat.c b/src/expat.c similarity index 100% rename from expat.c rename to src/expat.c diff --git a/expat.h b/src/expat.h similarity index 100% rename from expat.h rename to src/expat.h diff --git a/fail.c b/src/fail.c similarity index 100% rename from fail.c rename to src/fail.c diff --git a/fail.h b/src/fail.h similarity index 100% rename from fail.h rename to src/fail.h diff --git a/fs.c b/src/fs.c similarity index 98% rename from fs.c rename to src/fs.c index 8a321b8..fd5cf4e 100644 --- a/fs.c +++ b/src/fs.c @@ -74,6 +74,11 @@ void set_item_title(const char* title) sanitize(item_title); } +const char* get_item_title() +{ + return item_title; +} + void feed_open(const char* title) { struct stat st; diff --git a/fs.h b/src/fs.h similarity index 97% rename from fs.h rename to src/fs.h index fbe53fe..7c94d00 100644 --- a/fs.h +++ b/src/fs.h @@ -17,6 +17,8 @@ #define AGG_FS_H void set_item_title(const char*); +const char* get_item_title(); + void set_item_desc(const char*); void set_item_date(const char*); void set_item_link(const char*); diff --git a/layer.c b/src/layer.c similarity index 100% rename from layer.c rename to src/layer.c diff --git a/layer.h b/src/layer.h similarity index 100% rename from layer.h rename to src/layer.h diff --git a/nomtime b/src/nomtime similarity index 100% rename from nomtime rename to src/nomtime diff --git a/rss.c b/src/rss.c similarity index 100% rename from rss.c rename to src/rss.c diff --git a/rss.h b/src/rss.h similarity index 100% rename from rss.h rename to src/rss.h diff --git a/stack.c b/src/stack.c similarity index 100% rename from stack.c rename to src/stack.c diff --git a/stack.h b/src/stack.h similarity index 100% rename from stack.h rename to src/stack.h diff --git a/text.c b/src/text.c similarity index 100% rename from text.c rename to src/text.c diff --git a/text.h b/src/text.h similarity index 100% rename from text.h rename to src/text.h diff --git a/tests_dev/Makefile b/tests_dev/Makefile new file mode 100644 index 0000000..33b580f --- /dev/null +++ b/tests_dev/Makefile @@ -0,0 +1,20 @@ +-include ../Make.config + +LDFLAGS=-lexpat +DEPS=../src/expat.o ../src/fail.o ../src/rss.o ../src/stack.o ../src/text.o ../src/layer.o ../src/fs.o +LIBS= +POBJ=tests.o +POUT=tests + +all: $(POUT) +run: $(POUT) + ./$(POUT) + +$(POUT): $(LIBS) $(POBJ) + $(CC) -I../src $(LDFLAGS) $(DEPS) $(LIBS) $(POBJ) -o $(POUT) + +clean: + $(RM) -f $(LIBS) $(POBJ) $(POUT) + +%.o: %.c + $(CC) $(CFLAGS) -c $< diff --git a/tests_dev.c b/tests_dev/tests.c similarity index 69% rename from tests_dev.c rename to tests_dev/tests.c index 85f1a6b..03e8a01 100644 --- a/tests_dev.c +++ b/tests_dev/tests.c @@ -17,11 +17,12 @@ #include #include -#include "text.h" -#include "layer.h" -#include "stack.h" +#include "../src/text.h" +#include "../src/layer.h" +#include "../src/fs.h" +#include "../src/stack.h" -#define TEST(expr) test(#expr, expr) +#define TEST(fun) test(#fun, fun()) void test(const char* expr, int res); int test_text_is_empty(); @@ -36,31 +37,43 @@ int test_stack_set_top(); int test_stack_next_prev(); int test_stack_set_next(); -int main() -{ - TEST(test_text_is_empty()); - TEST(test_text_enable()); - TEST(test_text_disable()); - TEST(test_text_write()); - TEST(test_text_clear()); - TEST(test_text_append()); - TEST(test_text_fill()); +int test_set_item_title(); +int test_get_item_title(); +int test_item_sanitize_title(); +int test_item_overflow(); - TEST(test_stack_set_top()); - TEST(test_stack_next_prev()); - TEST(test_stack_set_next()); +unsigned int failures = 0; - return 0; +int main() +{ + TEST(test_text_is_empty); + TEST(test_text_enable); + TEST(test_text_disable); + TEST(test_text_write); + TEST(test_text_clear); + TEST(test_text_append); + TEST(test_text_fill); + + TEST(test_stack_set_top); + TEST(test_stack_next_prev); + TEST(test_stack_set_next); + + TEST(test_set_item_title); + TEST(test_get_item_title); + TEST(test_item_sanitize_title); + TEST(test_item_overflow); + + return failures; } void test(const char* expr, int res) { printf(" %-32s: %s\n", expr, res ? "OK" : "FAIL"); - if (!res) exit(1); + if (!res) { + ++failures; + } } - - int test_text_is_empty() { return strcmp("", text_get()) == 0; @@ -112,8 +125,6 @@ int test_text_fill() return strncmp(buf, text_get(), BUFSIZE) != 0; } - - int test_stack_set_top() { struct Layer mock; @@ -151,3 +162,39 @@ int test_stack_set_next() return stack_top()->enter == mock.enter && stack_top()->leave == mock.leave; } + +int test_set_item_title() +{ + set_item_title("foo"); + return 1; +} + +int test_get_item_title() +{ + return strcmp("foo", get_item_title()) == 0; +} + +int test_item_sanitize_title() +{ + set_item_title("../../foo"); + return strcmp("..\\..\\foo", get_item_title()) == 0; +} + +int test_item_overflow() +{ + #define MAXLEN 8192 + + char buf[BUFSIZE]; + char exp[MAXLEN + 1]; + + memset(buf, ' ', BUFSIZE); + memset(exp, ' ', MAXLEN + 1); + /* FIXME */ + /* exp[MAXLEN - 3] = '.'; */ + /* exp[MAXLEN - 2] = '.'; */ + /* exp[MAXLEN - 1] = '.'; */ + exp[MAXLEN] = 0; + + set_item_title(buf); + return strcmp(exp, get_item_title()) == 0; +} diff --git a/tests_usr/Makefile b/tests_usr/Makefile new file mode 100644 index 0000000..8e2a579 --- /dev/null +++ b/tests_usr/Makefile @@ -0,0 +1,8 @@ +-include ../Make.config + +TESTS=tests + +all: $(TESTS) + +run: $(TESTS) + ./$(TESTS) diff --git a/tests_titlelate.rss b/tests_usr/late_title.rss similarity index 100% rename from tests_titlelate.rss rename to tests_usr/late_title.rss diff --git a/tests_long.rss b/tests_usr/long.rss similarity index 100% rename from tests_long.rss rename to tests_usr/long.rss diff --git a/tests_titleless.rss b/tests_usr/no_title.rss similarity index 100% rename from tests_titleless.rss rename to tests_usr/no_title.rss diff --git a/tests.rss b/tests_usr/sample.rss similarity index 100% rename from tests.rss rename to tests_usr/sample.rss diff --git a/tests_simple_descriptions.rss b/tests_usr/simple_d.rss similarity index 100% rename from tests_simple_descriptions.rss rename to tests_usr/simple_d.rss diff --git a/tests_simple_titles.rss b/tests_usr/simple_t.rss similarity index 100% rename from tests_simple_titles.rss rename to tests_usr/simple_t.rss diff --git a/tests_usr.sh b/tests_usr/tests similarity index 91% rename from tests_usr.sh rename to tests_usr/tests index 731d189..8c9d4c7 100755 --- a/tests_usr.sh +++ b/tests_usr/tests @@ -13,7 +13,7 @@ ITEM3="Item 3" function agg_run() { - cat "$1" | ./agg + cat "$1" | ../src/agg res=$? if [ $res -ne 0 ]; then echo "Failed to run agg ($res)." @@ -23,7 +23,7 @@ function agg_run() function agg_fail() { - cat "$1" | ./agg + cat "$1" | ../src/agg res=$? if [ $res -eq 0 ]; then echo "Failed to fail running agg." @@ -33,7 +33,7 @@ function agg_fail() function agg_clean() { - find "$FEED" -type f -exec ./nomtime rm '{}' \; + find "$FEED" -type f -exec ../src/nomtime rm '{}' \; res=$? if [ $res -ne 0 ]; then echo "Failed to run nomtime." @@ -131,27 +131,27 @@ echo "Cleaning directory..." cleanup echo "Running agg on feed without title..." -agg_fail tests_titleless.rss +agg_fail no_title.rss t test_item_missing echo "Running agg on feed with title after items..." -agg_fail tests_titlelate.rss +agg_fail late_title.rss t test_item_missing echo "Running agg on simple feed (titles)..." -agg_run tests_simple_titles.rss +agg_run simple_t.rss t test_simple_t_feed_exists t test_simple_t_item_exists t test_simple_t_item_date t test_simple_t_item_contents echo "Running agg on simple feed (descriptions)..." -agg_run tests_simple_descriptions.rss +agg_run simple_d.rss t test_simple_d_feed_exists t test_simple_d_item_contents -echo "Running agg on missing directory..." -agg_run tests.rss +echo "Running agg on sample feed (directory missing)..." +agg_run sample.rss t test_complete_feed_exists t test_complete_feed_date t test_complete_item1_exists @@ -164,8 +164,8 @@ t test_complete_item1_contents t test_complete_item2_contents t test_complete_item3_contents -echo "Running agg on up-to-date directory..." -agg_run tests.rss +echo "Running agg sample feed (up to date) ..." +agg_run sample.rss t test_complete_feed_exists t test_complete_feed_date t test_complete_item1_exists @@ -184,8 +184,8 @@ t test_complete_feed_exists t test_complete_feed_date t test_complete_feed_empty -echo "Running agg on clean up-to-date directory..." -agg_run tests.rss +echo "Running agg on sample feed (directory up to date but empty)..." +agg_run sample.rss t test_complete_feed_exists t test_complete_feed_date t test_complete_feed_empty @@ -193,8 +193,8 @@ t test_complete_feed_empty echo "Changing mtime..." touch -md "1970-01-01 00:00:00.000000000 +0000" "$FEED" -echo "Running agg on clean outdated directory..." -agg_run tests.rss +echo "Running agg on sample feed (directory outdated and empty)..." +agg_run sample.rss t test_complete_feed_exists t test_complete_feed_date t test_complete_item1_exists @@ -208,7 +208,7 @@ t test_complete_item2_contents t test_complete_item3_contents echo "Running agg on feed with long items..." -agg_run tests_long.rss +agg_run long.rss t test_long_feed_exists t test_long_item_exists t test_long_item_contents -- 2.11.4.GIT