X-Git-Url: http://wpitchoune.net/gitweb/?p=psensor-pkg-debian.git;a=blobdiff_plain;f=tests%2Ftest_io_dir_list.c;fp=tests%2Ftest_io_dir_list.c;h=29a9c31fa053011e74a5199956eed24a3551613e;hp=0000000000000000000000000000000000000000;hb=dcd813f21c83592155f712ff1acf450b483d8072;hpb=f055e7507526592d3a74c652f5f053701614c9c0 diff --git a/tests/test_io_dir_list.c b/tests/test_io_dir_list.c new file mode 100644 index 0000000..29a9c31 --- /dev/null +++ b/tests/test_io_dir_list.c @@ -0,0 +1,105 @@ +/* + * 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 + +#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(stderr, "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 = tests_dir_list(); + + if (failures) + exit(EXIT_FAILURE); + else + exit(EXIT_SUCCESS); +}