From 27b116a64069ba0c0d734073fd33b5fb67958024 Mon Sep 17 00:00:00 2001 From: Antti Ajanki Date: Tue, 6 Aug 2013 18:05:44 +0300 Subject: Hide duplicate links --- tests/libwebvi_tests.c | 4 ++++ tests/linkextractor_tests.c | 42 ++++++++++++++++++++++++++++++++++++++++++ tests/linkextractor_tests.h | 2 ++ 3 files changed, 48 insertions(+) (limited to 'tests') diff --git a/tests/libwebvi_tests.c b/tests/libwebvi_tests.c index 4d57a94..f7975af 100644 --- a/tests/libwebvi_tests.c +++ b/tests/libwebvi_tests.c @@ -45,6 +45,10 @@ int main(int argc, char** argv) link_extractor_fixture_setup, test_link_extractor_title_overrides_content, link_extractor_fixture_teardown); + g_test_add("/linkextractor/html_title", LinkExtractorFixture, 0, + link_extractor_fixture_setup, + test_link_extractor_remove_duplicates, + link_extractor_fixture_teardown); g_test_add_func("/menubuilder/mainmenu", test_mainmenu); g_test_add("/menubuilder/title", MenuBuilderFixture, 0, diff --git a/tests/linkextractor_tests.c b/tests/linkextractor_tests.c index 60deba0..7fe9afc 100644 --- a/tests/linkextractor_tests.c +++ b/tests/linkextractor_tests.c @@ -44,6 +44,17 @@ "ignored" \ "" +#define HTML_DUPLICATE_HREF1 "http://example.com/test/1" +#define HTML_DUPLICATE_TITLE1 "First link" +#define HTML_DUPLICATE_HREF2 "http://example.com/test/2" +#define HTML_DUPLICATE_TITLE2 "Second link" +#define HTML_DUPLICATE_LINKS "" \ + "d1" \ + "" HTML_DUPLICATE_TITLE1 "" \ + "" HTML_DUPLICATE_TITLE2 "" \ + "d2" \ + "" + void link_extractor_fixture_setup(LinkExtractorFixture *fixture, gconstpointer test_data) { @@ -175,3 +186,34 @@ void test_link_extractor_title_overrides_content( g_assert(strcmp(title, HTML6_TITLE) == 0); g_ptr_array_free(links, TRUE); } + +void test_link_extractor_remove_duplicates(LinkExtractorFixture *fixture, + gconstpointer test_data) +{ + link_extractor_append(fixture->extractor, HTML_DUPLICATE_LINKS, + strlen(HTML_DUPLICATE_LINKS)); + GPtrArray *links = link_extractor_get_links(fixture->extractor); + g_assert(links); + g_assert(links->len == 2); + + const struct Link *link; + const char *href; + const char *title; + link = g_ptr_array_index(links, 0); + href = link_get_href(link); + g_assert(href); + g_assert(strcmp(href, HTML_DUPLICATE_HREF1) == 0); + title = link_get_title(link); + g_assert(title); + g_assert(strcmp(title, HTML_DUPLICATE_TITLE1) == 0); + + link = g_ptr_array_index(links, 1); + href = link_get_href(link); + g_assert(href); + g_assert(strcmp(href, HTML_DUPLICATE_HREF2) == 0); + title = link_get_title(link); + g_assert(title); + g_assert(strcmp(title, HTML_DUPLICATE_TITLE2) == 0); + + g_ptr_array_free(links, TRUE); +} diff --git a/tests/linkextractor_tests.h b/tests/linkextractor_tests.h index 62cc52f..cea6e2d 100644 --- a/tests/linkextractor_tests.h +++ b/tests/linkextractor_tests.h @@ -28,5 +28,7 @@ void test_link_extractor_html_title(LinkExtractorFixture *fixture, gconstpointer test_data); void test_link_extractor_title_overrides_content(LinkExtractorFixture *fixture, gconstpointer test_data); +void test_link_extractor_remove_duplicates(LinkExtractorFixture *fixture, + gconstpointer test_data); #endif // LINK_EXTRACTOR_TESTS_H -- cgit v1.2.3