diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-05-28 01:27:28 -0300 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-05-28 01:27:28 -0300 |
commit | b65ed83643c8964dc80ddf0e44a08cdea8eaba49 (patch) | |
tree | bee2403792f55f124eb0d4cb8d0fa8613efebdc5 | |
parent | 6d78665c9bf1b6d7b3445bd7ea09e7c0b2fc09bb (diff) | |
download | blogc-b65ed83643c8964dc80ddf0e44a08cdea8eaba49.tar.gz blogc-b65ed83643c8964dc80ddf0e44a08cdea8eaba49.tar.bz2 blogc-b65ed83643c8964dc80ddf0e44a08cdea8eaba49.zip |
loader: implemented pagination filter
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/loader.c | 37 | ||||
-rw-r--r-- | tests/check_loader.c | 469 |
3 files changed, 508 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index d79fc47..409d880 100644 --- a/configure.ac +++ b/configure.ac @@ -94,6 +94,8 @@ AM_CONDITIONAL([USE_CMOCKA], [test "x$have_cmocka" = "xyes"]) AC_CHECK_HEADERS([sys/types.h sys/stat.h time.h]) +AC_SEARCH_LIBS([ceilf], [m]) + AC_CONFIG_FILES([ Makefile ]) diff --git a/src/loader.c b/src/loader.c index a48c9dc..2d8ebf5 100644 --- a/src/loader.c +++ b/src/loader.c @@ -10,6 +10,7 @@ #include <config.h> #endif /* HAVE_CONFIG_H */ +#include <math.h> #include <stdio.h> #include <string.h> #include "utils/utils.h" @@ -102,6 +103,21 @@ blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err) unsigned int with_date = 0; const char *filter_tag = b_trie_lookup(conf, "FILTER_TAG"); + const char *filter_page = b_trie_lookup(conf, "FILTER_PAGE"); + const char *filter_per_page = b_trie_lookup(conf, "FILTER_PER_PAGE"); + + long page = strtol(filter_page != NULL ? filter_page : "", NULL, 10); + if (page <= 0) + page = 1; + long per_page = strtol(filter_per_page != NULL ? filter_per_page : "10", + NULL, 10); + if (per_page <= 0) + per_page = 10; + + // poor man's pagination + unsigned int start = (page - 1) * per_page; + unsigned int end = start + per_page; + unsigned int counter = 0; for (b_slist_t *tmp = l; tmp != NULL; tmp = tmp->next) { char *f = tmp->data; @@ -134,6 +150,14 @@ blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err) continue; } } + if (filter_page != NULL) { + if (counter < start || counter >= end) { + counter++; + b_trie_free(s); + continue; + } + counter++; + } if (b_trie_lookup(s, "DATE") != NULL) with_date++; rv = b_slist_append(rv, s); @@ -168,5 +192,18 @@ blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err) } } + if (filter_page != NULL) { + unsigned int last_page = ceilf(((float) counter) / per_page); + b_trie_insert(conf, "CURRENT_PAGE", b_strdup_printf("%ld", page)); + if (page > 1) + b_trie_insert(conf, "PREVIOUS_PAGE", b_strdup_printf("%ld", page - 1)); + if (page < last_page) + b_trie_insert(conf, "NEXT_PAGE", b_strdup_printf("%ld", page + 1)); + if (b_slist_length(rv) > 0) + b_trie_insert(conf, "FIRST_PAGE", b_strdup("1")); + if (last_page > 0) + b_trie_insert(conf, "LAST_PAGE", b_strdup_printf("%d", last_page)); + } + return rv; } diff --git a/tests/check_loader.c b/tests/check_loader.c index f570297..865d598 100644 --- a/tests/check_loader.c +++ b/tests/check_loader.c @@ -223,6 +223,469 @@ test_source_parse_from_files_filter_by_tag(void **state) static void +test_source_parse_from_files_filter_by_page(void **state) +{ + will_return(__wrap_blogc_file_get_contents, "bola1.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 123\n" + "DATE: 2001-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola2.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 456\n" + "DATE: 2002-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola3.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 789\n" + "DATE: 2003-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola4.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7891\n" + "DATE: 2004-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola5.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7892\n" + "DATE: 2005-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola6.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7893\n" + "DATE: 2006-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola7.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7894\n" + "DATE: 2007-02-03 04:05:06\n" + "--------\n" + "bola")); + blogc_error_t *err = NULL; + b_slist_t *s = NULL; + s = b_slist_append(s, b_strdup("bola1.txt")); + s = b_slist_append(s, b_strdup("bola2.txt")); + s = b_slist_append(s, b_strdup("bola3.txt")); + s = b_slist_append(s, b_strdup("bola4.txt")); + s = b_slist_append(s, b_strdup("bola5.txt")); + s = b_slist_append(s, b_strdup("bola6.txt")); + s = b_slist_append(s, b_strdup("bola7.txt")); + b_trie_t *c = b_trie_new(free); + b_trie_insert(c, "FILTER_PAGE", b_strdup("1")); + b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2")); + b_slist_t *t = blogc_source_parse_from_files(c, s, &err); + assert_null(err); + assert_non_null(t); + assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items + assert_int_equal(b_trie_size(c), 10); + assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1"); + assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola2"); + assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06"); + assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06"); + assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "1"); + assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2"); + assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "1"); + assert_string_equal(b_trie_lookup(c, "NEXT_PAGE"), "2"); + assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1"); + assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "4"); + b_trie_free(c); + b_slist_free_full(s, free); + b_slist_free_full(t, (b_free_func_t) b_trie_free); +} + + +static void +test_source_parse_from_files_filter_by_page2(void **state) +{ + will_return(__wrap_blogc_file_get_contents, "bola1.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 123\n" + "DATE: 2001-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola2.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 456\n" + "DATE: 2002-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola3.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 789\n" + "DATE: 2003-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola4.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7891\n" + "DATE: 2004-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola5.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7892\n" + "DATE: 2005-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola6.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7893\n" + "DATE: 2006-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola7.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7894\n" + "DATE: 2007-02-03 04:05:06\n" + "--------\n" + "bola")); + blogc_error_t *err = NULL; + b_slist_t *s = NULL; + s = b_slist_append(s, b_strdup("bola1.txt")); + s = b_slist_append(s, b_strdup("bola2.txt")); + s = b_slist_append(s, b_strdup("bola3.txt")); + s = b_slist_append(s, b_strdup("bola4.txt")); + s = b_slist_append(s, b_strdup("bola5.txt")); + s = b_slist_append(s, b_strdup("bola6.txt")); + s = b_slist_append(s, b_strdup("bola7.txt")); + b_trie_t *c = b_trie_new(free); + b_trie_insert(c, "FILTER_PAGE", b_strdup("3")); + b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2")); + b_slist_t *t = blogc_source_parse_from_files(c, s, &err); + assert_null(err); + assert_non_null(t); + assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items + assert_int_equal(b_trie_size(c), 11); + assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola5"); + assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola6"); + assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06"); + assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2006-02-03 04:05:06"); + assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "3"); + assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2"); + assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "3"); + assert_string_equal(b_trie_lookup(c, "PREVIOUS_PAGE"), "2"); + assert_string_equal(b_trie_lookup(c, "NEXT_PAGE"), "4"); + assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1"); + assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "4"); + b_trie_free(c); + b_slist_free_full(s, free); + b_slist_free_full(t, (b_free_func_t) b_trie_free); +} + + +static void +test_source_parse_from_files_filter_by_page3(void **state) +{ + will_return(__wrap_blogc_file_get_contents, "bola1.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 123\n" + "DATE: 2001-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola2.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 456\n" + "DATE: 2002-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola3.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 789\n" + "DATE: 2003-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola4.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7891\n" + "DATE: 2004-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola5.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7892\n" + "DATE: 2005-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola6.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7893\n" + "DATE: 2006-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola7.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7894\n" + "DATE: 2007-02-03 04:05:06\n" + "--------\n" + "bola")); + blogc_error_t *err = NULL; + b_slist_t *s = NULL; + s = b_slist_append(s, b_strdup("bola1.txt")); + s = b_slist_append(s, b_strdup("bola2.txt")); + s = b_slist_append(s, b_strdup("bola3.txt")); + s = b_slist_append(s, b_strdup("bola4.txt")); + s = b_slist_append(s, b_strdup("bola5.txt")); + s = b_slist_append(s, b_strdup("bola6.txt")); + s = b_slist_append(s, b_strdup("bola7.txt")); + b_trie_t *c = b_trie_new(free); + b_trie_insert(c, "FILTER_PAGE", b_strdup("1")); + b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2")); + b_slist_t *t = blogc_source_parse_from_files(c, s, &err); + assert_null(err); + assert_non_null(t); + assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items + assert_int_equal(b_trie_size(c), 10); + assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1"); + assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola2"); + assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06"); + assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06"); + assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "1"); + assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2"); + assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "1"); + assert_string_equal(b_trie_lookup(c, "NEXT_PAGE"), "2"); + assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1"); + assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "4"); + b_trie_free(c); + b_slist_free_full(s, free); + b_slist_free_full(t, (b_free_func_t) b_trie_free); +} + + +static void +test_source_parse_from_files_filter_by_page_and_tag(void **state) +{ + will_return(__wrap_blogc_file_get_contents, "bola1.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 123\n" + "DATE: 2001-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola2.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 456\n" + "DATE: 2002-02-03 04:05:06\n" + "TAGS: chunda\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola3.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 789\n" + "DATE: 2003-02-03 04:05:06\n" + "TAGS: chunda, bola\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola4.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7891\n" + "DATE: 2004-02-03 04:05:06\n" + "TAGS: bola\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola5.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7892\n" + "DATE: 2005-02-03 04:05:06\n" + "TAGS: chunda\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola6.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7893\n" + "DATE: 2006-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola7.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7894\n" + "DATE: 2007-02-03 04:05:06\n" + "TAGS: yay, chunda\n" + "--------\n" + "bola")); + blogc_error_t *err = NULL; + b_slist_t *s = NULL; + s = b_slist_append(s, b_strdup("bola1.txt")); + s = b_slist_append(s, b_strdup("bola2.txt")); + s = b_slist_append(s, b_strdup("bola3.txt")); + s = b_slist_append(s, b_strdup("bola4.txt")); + s = b_slist_append(s, b_strdup("bola5.txt")); + s = b_slist_append(s, b_strdup("bola6.txt")); + s = b_slist_append(s, b_strdup("bola7.txt")); + b_trie_t *c = b_trie_new(free); + b_trie_insert(c, "FILTER_TAG", b_strdup("chunda")); + b_trie_insert(c, "FILTER_PAGE", b_strdup("2")); + b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2")); + b_slist_t *t = blogc_source_parse_from_files(c, s, &err); + assert_null(err); + assert_non_null(t); + assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items + assert_int_equal(b_trie_size(c), 11); + assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola5"); + assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola7"); + assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06"); + assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2007-02-03 04:05:06"); + assert_string_equal(b_trie_lookup(c, "FILTER_TAG"), "chunda"); + assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "2"); + assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2"); + assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "2"); + assert_string_equal(b_trie_lookup(c, "PREVIOUS_PAGE"), "1"); + assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1"); + assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "2"); + b_trie_free(c); + b_slist_free_full(s, free); + b_slist_free_full(t, (b_free_func_t) b_trie_free); +} + + +static void +test_source_parse_from_files_filter_by_page_invalid(void **state) +{ + will_return(__wrap_blogc_file_get_contents, "bola1.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 123\n" + "DATE: 2001-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola2.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 456\n" + "DATE: 2002-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola3.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 789\n" + "DATE: 2003-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola4.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7891\n" + "DATE: 2004-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola5.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7892\n" + "DATE: 2005-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola6.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7893\n" + "DATE: 2006-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola7.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7894\n" + "DATE: 2007-02-03 04:05:06\n" + "--------\n" + "bola")); + blogc_error_t *err = NULL; + b_slist_t *s = NULL; + s = b_slist_append(s, b_strdup("bola1.txt")); + s = b_slist_append(s, b_strdup("bola2.txt")); + s = b_slist_append(s, b_strdup("bola3.txt")); + s = b_slist_append(s, b_strdup("bola4.txt")); + s = b_slist_append(s, b_strdup("bola5.txt")); + s = b_slist_append(s, b_strdup("bola6.txt")); + s = b_slist_append(s, b_strdup("bola7.txt")); + b_trie_t *c = b_trie_new(free); + b_trie_insert(c, "FILTER_PAGE", b_strdup("-1")); + b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2")); + b_slist_t *t = blogc_source_parse_from_files(c, s, &err); + assert_null(err); + assert_non_null(t); + assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items + assert_int_equal(b_trie_size(c), 10); + assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1"); + assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola2"); + assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06"); + assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06"); + assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "-1"); + assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2"); + assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "1"); + assert_string_equal(b_trie_lookup(c, "NEXT_PAGE"), "2"); + assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1"); + assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "4"); + b_trie_free(c); + b_slist_free_full(s, free); + b_slist_free_full(t, (b_free_func_t) b_trie_free); +} + + +static void +test_source_parse_from_files_filter_by_page_invalid2(void **state) +{ + will_return(__wrap_blogc_file_get_contents, "bola1.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 123\n" + "DATE: 2001-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola2.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 456\n" + "DATE: 2002-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola3.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 789\n" + "DATE: 2003-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola4.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7891\n" + "DATE: 2004-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola5.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7892\n" + "DATE: 2005-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola6.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7893\n" + "DATE: 2006-02-03 04:05:06\n" + "--------\n" + "bola")); + will_return(__wrap_blogc_file_get_contents, "bola7.txt"); + will_return(__wrap_blogc_file_get_contents, b_strdup( + "ASD: 7894\n" + "DATE: 2007-02-03 04:05:06\n" + "--------\n" + "bola")); + blogc_error_t *err = NULL; + b_slist_t *s = NULL; + s = b_slist_append(s, b_strdup("bola1.txt")); + s = b_slist_append(s, b_strdup("bola2.txt")); + s = b_slist_append(s, b_strdup("bola3.txt")); + s = b_slist_append(s, b_strdup("bola4.txt")); + s = b_slist_append(s, b_strdup("bola5.txt")); + s = b_slist_append(s, b_strdup("bola6.txt")); + s = b_slist_append(s, b_strdup("bola7.txt")); + b_trie_t *c = b_trie_new(free); + b_trie_insert(c, "FILTER_PAGE", b_strdup("5")); + b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2")); + b_slist_t *t = blogc_source_parse_from_files(c, s, &err); + assert_null(err); + assert_null(t); + b_trie_free(c); + b_slist_free_full(s, free); +} + + +static void test_source_parse_from_files_without_all_dates(void **state) { will_return(__wrap_blogc_fprintf, stderr); @@ -295,6 +758,12 @@ main(void) unit_test(test_source_parse_from_file_null), unit_test(test_source_parse_from_files), unit_test(test_source_parse_from_files_filter_by_tag), + unit_test(test_source_parse_from_files_filter_by_page), + unit_test(test_source_parse_from_files_filter_by_page2), + unit_test(test_source_parse_from_files_filter_by_page3), + unit_test(test_source_parse_from_files_filter_by_page_and_tag), + unit_test(test_source_parse_from_files_filter_by_page_invalid), + unit_test(test_source_parse_from_files_filter_by_page_invalid2), unit_test(test_source_parse_from_files_without_all_dates), unit_test(test_source_parse_from_files_null), }; |