diff options
author | Brendan Long <self@brendanlong.com> | 2019-07-13 21:15:33 +0300 |
---|---|---|
committer | Brendan Long <self@brendanlong.com> | 2019-07-13 22:04:50 +0300 |
commit | 72848b0b16c207645e65b6c3e6cbdf0d4f41e7eb (patch) | |
tree | a4b107179ae616ba05d99b86b2cae9d5787cb79f | |
parent | f4609b7dcfcf596c3746e1734575c53ea72269ab (diff) |
Add tests for htmlclean
-rw-r--r-- | libraries/htmlclean/htmlclean.c | 2 | ||||
-rw-r--r-- | libraries/htmlclean/htmlclean.h | 2 | ||||
-rw-r--r-- | libraries/htmlclean/meson.build | 18 | ||||
-rw-r--r-- | libraries/htmlclean/test_htmlclean.c | 71 |
4 files changed, 91 insertions, 2 deletions
diff --git a/libraries/htmlclean/htmlclean.c b/libraries/htmlclean/htmlclean.c index 2f17cbc2..25e4c582 100644 --- a/libraries/htmlclean/htmlclean.c +++ b/libraries/htmlclean/htmlclean.c @@ -79,7 +79,7 @@ char *cleantext(GumboNode *node) } } -char *htmlclean_strip_html(char *input) +char *htmlclean_strip_html(const char *input) { char *cleaned = NULL; if (input != NULL) diff --git a/libraries/htmlclean/htmlclean.h b/libraries/htmlclean/htmlclean.h index 20fe9b60..c05ec2d7 100644 --- a/libraries/htmlclean/htmlclean.h +++ b/libraries/htmlclean/htmlclean.h @@ -4,4 +4,4 @@ * Strips HTML from the input string and returns just the text. * The resulting string must be freed when you're done with it. */ -char *htmlclean_strip_html(char *); +char *htmlclean_strip_html(const char *); diff --git a/libraries/htmlclean/meson.build b/libraries/htmlclean/meson.build index e1050e88..0c84425d 100644 --- a/libraries/htmlclean/meson.build +++ b/libraries/htmlclean/meson.build @@ -11,3 +11,21 @@ htmlclean_main = executable( 'htmlclean_main', 'main.c', link_with: htmlclean_lib) + +htmlclean_test = executable( + 'test_htmlclean', + [ + 'test_htmlclean.c' + ], + dependencies: [ + glib, + gtk + ], + link_with: htmlclean_lib +) + +if gtester.found() + test('Htmlclean library', gtester, args:['-k', '-o', meson.build_root() + '/htmlclean.gtester.log', htmlclean_test]) +else + test('Htmlclean library', htmlclean_test) +endif diff --git a/libraries/htmlclean/test_htmlclean.c b/libraries/htmlclean/test_htmlclean.c new file mode 100644 index 00000000..d8c37ad6 --- /dev/null +++ b/libraries/htmlclean/test_htmlclean.c @@ -0,0 +1,71 @@ +#include <glib.h> + +#include "htmlclean.h" + +typedef struct { + const char* input; + const char* output; +} inout_t; + +static void test_change(const void* vinout) +{ + const inout_t* inout = vinout; + g_assert_cmpstr (htmlclean_strip_html(inout->input), ==, inout->output); +} + +static void test_no_change(const void* input) +{ + const inout_t inout = { + .input = input, + .output = input + }; + test_change(&inout); +} + +int main(int argc, char** argv) +{ + g_test_init (&argc, &argv, NULL); + + g_test_add_data_func ( + "/htmlclean/change/removehtml", + &(inout_t){ + "this <pre>string</pre> contains html", + "this string contains html" + }, + test_change); + + g_test_add_data_func ( + "/htmlclean/change/stripinput", + &(inout_t){ + " this has spaces around it ", + "this has spaces around it" + }, + test_change); + + g_test_add_data_func ( + "/htmlclean/nochange/basic", + "this is a normal string", + test_no_change + ); + + // g_test_add_data_func ( + // "/htmlclean/nochange/escapedhtml", + // "this string contains & escaped HTML", + // test_no_change + // ); + + // Previous versions of the parser crashed or hung when given these inputs + g_test_add_data_func ( + "/htmlclean/nochange/justopen", + "<", + test_no_change + ); + + g_test_add_data_func ( + "/htmlclean/nochange/justamp", + "&", + test_no_change + ); + + return g_test_run (); +} |