From da5ec078afae896e95fb4a4982be46db84042083 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Sat, 17 Dec 2011 00:41:43 +0000 Subject: [PATCH] dir list test --- src/lib/pio.c | 1 - tests/Makefile.am | 14 ++++-- tests/Makefile.in | 23 +++++++--- tests/test-io-dir-list.sh | 11 +++++ tests/test_io_dir_list.c | 106 +++++++++++++++++++++++++++++++++++++++++++++ tests/test_url_encode.c | 3 +- tests/test_url_normalize.c | 5 +-- 7 files changed, 148 insertions(+), 15 deletions(-) create mode 100755 tests/test-io-dir-list.sh create mode 100644 tests/test_io_dir_list.c diff --git a/src/lib/pio.c b/src/lib/pio.c index 54d9efb..3cfb02d 100644 --- a/src/lib/pio.c +++ b/src/lib/pio.c @@ -86,4 +86,3 @@ void paths_free(char **paths) free(paths); } - diff --git a/tests/Makefile.am b/tests/Makefile.am index a030cd1..08788b8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,9 +2,13 @@ check-local: checkpatch.pl find $(top_srcdir)/src -name \*.c -exec $(srcdir)/checkpatch.pl -q --no-tree -emacs -f {} \; find $(top_srcdir)/src -name \*.h -exec $(srcdir)/checkpatch.pl -q --no-tree -emacs -f {} \; -EXTRA_DIST = checkpatch.pl +EXTRA_DIST = checkpatch.pl data test-io-dir-list.sh -check_PROGRAMS = test-url-encode test-url-normalize +check_PROGRAMS = test-io-dir-list \ + test-url-encode \ + test-url-normalize + +AM_CPPFLAGS = -pedantic test_url_encode_SOURCES = test_url_encode.c test_url_encode_LDADD = ../src/lib/libpsensor.a @@ -12,5 +16,9 @@ test_url_encode_LDADD = ../src/lib/libpsensor.a test_url_normalize_SOURCES = test_url_normalize.c test_url_normalize_LDADD = ../src/lib/libpsensor.a +test_io_dir_list_SOURCES = test_io_dir_list.c +test_io_dir_list_LDADD = ../src/lib/libpsensor.a + TESTS = test-url-encode \ - test-url-normalize \ No newline at end of file + test-url-normalize \ + test-io-dir-list.sh \ No newline at end of file diff --git a/tests/Makefile.in b/tests/Makefile.in index 4674ec8..58331d9 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -33,8 +33,10 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -check_PROGRAMS = test-url-encode$(EXEEXT) test-url-normalize$(EXEEXT) -TESTS = test-url-encode$(EXEEXT) test-url-normalize$(EXEEXT) +check_PROGRAMS = test-io-dir-list$(EXEEXT) test-url-encode$(EXEEXT) \ + test-url-normalize$(EXEEXT) +TESTS = test-url-encode$(EXEEXT) test-url-normalize$(EXEEXT) \ + test-io-dir-list.sh subdir = tests DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -45,6 +47,9 @@ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = +am_test_io_dir_list_OBJECTS = test_io_dir_list.$(OBJEXT) +test_io_dir_list_OBJECTS = $(am_test_io_dir_list_OBJECTS) +test_io_dir_list_DEPENDENCIES = ../src/lib/libpsensor.a am_test_url_encode_OBJECTS = test_url_encode.$(OBJEXT) test_url_encode_OBJECTS = $(am_test_url_encode_OBJECTS) test_url_encode_DEPENDENCIES = ../src/lib/libpsensor.a @@ -59,8 +64,9 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ -SOURCES = $(test_url_encode_SOURCES) $(test_url_normalize_SOURCES) -DIST_SOURCES = $(test_url_encode_SOURCES) \ +SOURCES = $(test_io_dir_list_SOURCES) $(test_url_encode_SOURCES) \ + $(test_url_normalize_SOURCES) +DIST_SOURCES = $(test_io_dir_list_SOURCES) $(test_url_encode_SOURCES) \ $(test_url_normalize_SOURCES) ETAGS = etags CTAGS = ctags @@ -213,11 +219,14 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -EXTRA_DIST = checkpatch.pl +EXTRA_DIST = checkpatch.pl data test-io-dir-list.sh +AM_CPPFLAGS = -pedantic test_url_encode_SOURCES = test_url_encode.c test_url_encode_LDADD = ../src/lib/libpsensor.a test_url_normalize_SOURCES = test_url_normalize.c test_url_normalize_LDADD = ../src/lib/libpsensor.a +test_io_dir_list_SOURCES = test_io_dir_list.c +test_io_dir_list_LDADD = ../src/lib/libpsensor.a all: all-am .SUFFIXES: @@ -255,6 +264,9 @@ $(am__aclocal_m4_deps): clean-checkPROGRAMS: -test -z "$(check_PROGRAMS)" || rm -f $(check_PROGRAMS) +test-io-dir-list$(EXEEXT): $(test_io_dir_list_OBJECTS) $(test_io_dir_list_DEPENDENCIES) + @rm -f test-io-dir-list$(EXEEXT) + $(LINK) $(test_io_dir_list_OBJECTS) $(test_io_dir_list_LDADD) $(LIBS) test-url-encode$(EXEEXT): $(test_url_encode_OBJECTS) $(test_url_encode_DEPENDENCIES) @rm -f test-url-encode$(EXEEXT) $(LINK) $(test_url_encode_OBJECTS) $(test_url_encode_LDADD) $(LIBS) @@ -268,6 +280,7 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_io_dir_list.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_url_encode.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_url_normalize.Po@am__quote@ diff --git a/tests/test-io-dir-list.sh b/tests/test-io-dir-list.sh new file mode 100755 index 0000000..a490473 --- /dev/null +++ b/tests/test-io-dir-list.sh @@ -0,0 +1,11 @@ +#/bin/sh + +mkdir -p data/empty_dir +mkdir -p data/2files_dir +touch data/2files_dir/one +touch data/2files_dir/two + +./test-io-dir-list || exit 1 + +rm data/2files_dir/one data/2files_dir/two +rmdir data/empty_dir data/2files_dir \ No newline at end of file diff --git a/tests/test_io_dir_list.c b/tests/test_io_dir_list.c new file mode 100644 index 0000000..7be8d7b --- /dev/null +++ b/tests/test_io_dir_list.c @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2010-2011 jeanfi@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include +#include + +#include "../src/lib/pio.h" + +static int test_empty_dir() +{ + int ret; + char **paths; + + paths = dir_list("data/empty_dir", NULL); + + ret = 0; + if (paths) { + if (*paths) { + ret = 1; + fprintf(stderr, "ERROR: list not empty %s\n", *paths); + } + + paths_free(paths); + } + + return ret; +} + +static int test_2files_dir() +{ + int ret, one, two; + char **paths, **cur; + + paths = dir_list("data/2files_dir", NULL); + + one = two = ret = 0; + + if (!paths) { + fprintf(stderr, "ERROR: list is NULL\n"); + return 1; + } + + cur = paths; + while(*cur) { + if (!strcmp(*cur, "data/2files_dir/one")) { + one++; + } else if (!strcmp(*cur, "data/2files_dir/two")) { + two++; + } else { + fprintf("ERROR: wrong item: %s\n", *cur); + + ret = 1; + } + + cur++; + } + + if (!ret && one == 1 && two == 1) + ret = 0; + else + ret = 1; + + paths_free(paths); + + return ret; +} + +static int tests_dir_list() { + int failures; + + failures += test_empty_dir(); + + failures += test_2files_dir(); + + return failures; +} + +int main(int argc, char **argv) +{ + int failures; + + failures = 0; + + failures += tests_dir_list(); + + if (failures) + exit(EXIT_FAILURE); + else + exit(EXIT_SUCCESS); +} diff --git a/tests/test_url_encode.c b/tests/test_url_encode.c index 3d7ed68..0b64aef 100644 --- a/tests/test_url_encode.c +++ b/tests/test_url_encode.c @@ -14,10 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - *02110-1301 USA + * 02110-1301 USA */ - #include #include #include diff --git a/tests/test_url_normalize.c b/tests/test_url_normalize.c index 1a76209..ef48203 100644 --- a/tests/test_url_normalize.c +++ b/tests/test_url_normalize.c @@ -14,10 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - *02110-1301 USA + * 02110-1301 USA */ - #include #include #include @@ -25,7 +24,6 @@ #include "../src/lib/url.h" - int test_url_normalize(const char *url, const char *ref_url) { int ret; @@ -48,7 +46,6 @@ int test_url_normalize(const char *url, const char *ref_url) return ret; } - int tests_url_normalize() { int failures; -- 2.7.4