From 6f9ff4486a2f37753152a50c77e1178520daf65f Mon Sep 17 00:00:00 2001 From: Andreas Waidler Date: Tue, 10 May 2011 21:58:23 +0200 Subject: [PATCH] Split tests_dev/tests.c into seperate files for each suite. --- Makefile | 3 +- TODO | 36 +++++++--------- tests_dev/Makefile | 2 +- tests_dev/stack.c | 40 +++++++++++++++++ tests_dev/stack.h | 23 ++++++++++ tests_dev/tests.c | 124 ++++------------------------------------------------- tests_dev/text.c | 54 +++++++++++++++++++++++ tests_dev/text.h | 27 ++++++++++++ 8 files changed, 169 insertions(+), 140 deletions(-) rewrite TODO (95%) create mode 100644 tests_dev/stack.c create mode 100644 tests_dev/stack.h create mode 100644 tests_dev/text.c create mode 100644 tests_dev/text.h diff --git a/Makefile b/Makefile index 1f46027..b7a820a 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,7 @@ all: make -C src tests: all - make -C tests_dev run - make -C tests_usr run + make -C tests_dev run && make -C tests_usr run install: all make -C src install diff --git a/TODO b/TODO dissimilarity index 95% index eeecd25..3a413df 100644 --- a/TODO +++ b/TODO @@ -1,21 +1,15 @@ -* QA - * refactor devtests - * test whether nomtime can handle complicated filenames - * more assertions - * replace assertions by proper error handling - * check whether new items are retrieved, but old ones are - not fetched - * check whether dates are handled properly (timezones!) -* fix remaining bugs (see README) -* future - * item overwrite only if date >= olddate - else notice, skip offending item, and do not change - feed date, continue but exit with error - (invariant: date of every unfetched item is > feed date) - * Make directories/items read-only. - * support lastBuildDate and pubDate for channels - * do not stop on first old item, consume whole feed - channel pubDate is not old. - * maybe use http last-modified? it is not reliable on - some servers, though, and probably needs ugly hacks - * atom +* test whether nomtime can handle complicated filenames +* more assertions +* do not stop on first old item, consume whole feed + channel pubDate is not old. +* check whether new items are retrieved, but old ones are + not written +* item overwrite only if date >= olddate + else notice, skip offending item, and do not change + feed date, continue but exit with error + (invariant: date of every unfetched item is > feed date) +* Make directories/items read-only. +* check whether dates are handled properly (timezones!) +* fix remaining bugs (see README) +* support lastBuildDate and pubDate for channels +* replace assertions by proper error handling diff --git a/tests_dev/Makefile b/tests_dev/Makefile index 39bdf3d..c81bc51 100644 --- a/tests_dev/Makefile +++ b/tests_dev/Makefile @@ -2,7 +2,7 @@ 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=fs.o +LIBS=fs.o text.o stack.o POBJ=tests.o POUT=tests diff --git a/tests_dev/stack.c b/tests_dev/stack.c new file mode 100644 index 0000000..d6a11c3 --- /dev/null +++ b/tests_dev/stack.c @@ -0,0 +1,40 @@ +#include "stack.h" +#include "../src/stack.h" + +int test_stack_set_top() +{ + struct Layer mock; + mock.enter = (void (*)(const char*, const char**)) 0x7E57AB1E; + mock.leave = (void (*)(const char*)) 0xCA11AB1E; + + stack_set(0, mock); + return stack_top()->enter == mock.enter + && stack_top()->leave == mock.leave; +} + +int test_stack_next_prev() +{ + struct Layer mock; + mock.enter = (void (*)(const char*, const char**)) 0x7E57AB1E; + mock.leave = (void (*)(const char*)) 0xCA11AB1E; + + /* Mock still set from method before. */ + + stack_next(); + stack_prev(); + + return stack_top()->enter == mock.enter + && stack_top()->leave == mock.leave; +} + +int test_stack_set_next() +{ + struct Layer mock; + mock.enter = (void (*)(const char*, const char**)) 0x7E57AB1E; + mock.leave = (void (*)(const char*)) 0xCA11AB1E; + + stack_set(1, mock); + stack_next(); + return stack_top()->enter == mock.enter + && stack_top()->leave == mock.leave; +} diff --git a/tests_dev/stack.h b/tests_dev/stack.h new file mode 100644 index 0000000..e0ca6cf --- /dev/null +++ b/tests_dev/stack.h @@ -0,0 +1,23 @@ +/* agg - the news aggregator + * Copyright (C) 2011 Andreas Waidler + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#ifndef AGG_TESTS_STACK_H +#define AGG_TESTS_STACK_H + +int test_stack_set_top(); +int test_stack_next_prev(); +int test_stack_set_next(); + +#endif diff --git a/tests_dev/tests.c b/tests_dev/tests.c index f0cd53c..1edef1d 100644 --- a/tests_dev/tests.c +++ b/tests_dev/tests.c @@ -18,31 +18,18 @@ #include #include "../src/config.h" -#include "../src/text.h" #include "../src/layer.h" -#include "../src/stack.h" #include "fs.h" +#include "text.h" +#include "stack.h" #define TEST(fun) test(#fun, fun()) -void test(const char* expr, int res); - -int test_text_is_empty(); -int test_text_enable(); -int test_text_disable(); -int test_text_write(); -int test_text_clear(); -int test_text_append(); -int test_text_fill(); - -int test_stack_set_top(); -int test_stack_next_prev(); -int test_stack_set_next(); - -unsigned int failures = 0; - -/* buffer must be >= text buffer. */ -#define TESTS_BUFSIZE (1024 * 1024) +void test(const char* expr, int res) +{ + printf(" %-32s: %s\n", expr, res ? "OK" : "FAIL"); + if (!res) exit(1); +} int main() { @@ -66,100 +53,5 @@ int main() TEST(test_fs_item_set_title); TEST(test_fs_item_get_title); - return failures; -} - -void test(const char* expr, int res) -{ - printf(" %-32s: %s\n", expr, res ? "OK" : "FAIL"); - if (!res) { - ++failures; - } -} - -int test_text_is_empty() -{ - return strcmp("", text_get()) == 0; -} - -int test_text_enable() -{ - text_enable(); - return 1; -} - -int test_text_disable() -{ - text_disable(); - return 1; -} - -int test_text_write() -{ - text_buffer("foobar", 3); - return strcmp("foo", text_get()) == 0; -} - -int test_text_clear() -{ - text_enable(); - if (!test_text_is_empty()) return 0; - - test_text_write(); - text_disable(); - return test_text_is_empty(); -} - -int test_text_append() -{ - text_buffer("foobar", 3); - text_buffer("foobar", 3); - return strcmp("foofoo", text_get()) == 0; -} - -int test_text_fill() -{ - char buf[TESTS_BUFSIZE]; - memset(buf, ' ', TESTS_BUFSIZE); - text_buffer(buf, TESTS_BUFSIZE); - - return strncmp(buf, text_get(), TESTS_BUFSIZE) != 0; -} - -int test_stack_set_top() -{ - struct Layer mock; - mock.enter = (void (*)(const char*, const char**)) 0x7E57AB1E; - mock.leave = (void (*)(const char*)) 0xCA11AB1E; - - stack_set(0, mock); - return stack_top()->enter == mock.enter - && stack_top()->leave == mock.leave; -} - -int test_stack_next_prev() -{ - struct Layer mock; - mock.enter = (void (*)(const char*, const char**)) 0x7E57AB1E; - mock.leave = (void (*)(const char*)) 0xCA11AB1E; - - /* Mock still set from method before. */ - - stack_next(); - stack_prev(); - - return stack_top()->enter == mock.enter - && stack_top()->leave == mock.leave; -} - -int test_stack_set_next() -{ - struct Layer mock; - mock.enter = (void (*)(const char*, const char**)) 0x7E57AB1E; - mock.leave = (void (*)(const char*)) 0xCA11AB1E; - - stack_set(1, mock); - stack_next(); - return stack_top()->enter == mock.enter - && stack_top()->leave == mock.leave; + return 0; } diff --git a/tests_dev/text.c b/tests_dev/text.c new file mode 100644 index 0000000..c3cd625 --- /dev/null +++ b/tests_dev/text.c @@ -0,0 +1,54 @@ +#include "text.h" +#include "../src/text.h" + +/* buffer must be >= text buffer. */ +#define TESTS_BUFSIZE (1024 * 1024) + +int test_text_is_empty() +{ + return strcmp("", text_get()) == 0; +} + +int test_text_enable() +{ + text_enable(); + return 1; +} + +int test_text_disable() +{ + text_disable(); + return 1; +} + +int test_text_write() +{ + text_buffer("foobar", 3); + return strcmp("foo", text_get()) == 0; +} + +int test_text_clear() +{ + text_enable(); + if (!test_text_is_empty()) return 0; + + test_text_write(); + text_disable(); + return test_text_is_empty(); +} + +int test_text_append() +{ + text_buffer("foobar", 3); + text_buffer("foobar", 3); + return strcmp("foofoo", text_get()) == 0; +} + +int test_text_fill() +{ + char buf[TESTS_BUFSIZE]; + memset(buf, ' ', TESTS_BUFSIZE); + text_buffer(buf, TESTS_BUFSIZE); + + return strncmp(buf, text_get(), TESTS_BUFSIZE) != 0; +} diff --git a/tests_dev/text.h b/tests_dev/text.h new file mode 100644 index 0000000..e1bef3d --- /dev/null +++ b/tests_dev/text.h @@ -0,0 +1,27 @@ +/* agg - the news aggregator + * Copyright (C) 2011 Andreas Waidler + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#ifndef AGG_TESTS_TEXT_H +#define AGG_TESTS_TEXT_H + +int test_text_is_empty(); +int test_text_enable(); +int test_text_disable(); +int test_text_write(); +int test_text_clear(); +int test_text_append(); +int test_text_fill(); + +#endif -- 2.11.4.GIT