Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/jangernert/FeedReader.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrendan Long <self@brendanlong.com>2018-08-26 18:56:05 +0300
committerBrendan Long <self@brendanlong.com>2018-08-26 19:43:16 +0300
commitf7366cc609059fdd0abe21218ee06284dcb0faf1 (patch)
tree66615eb43f7535ee4edd1243c6b93dbea679d512 /libraries
parent085d9da0b9d7fa55e2d6ec0f43a95f5662325c96 (diff)
libvilistextum: Add tests
A lot of these are broken and commented out so far. I changed libvilistetum to add \n between lines, not just at the end of every line to make it easier to do "nothing should change" tests. Part of #741
Diffstat (limited to 'libraries')
-rw-r--r--libraries/libVilistextum/fileio.c5
-rw-r--r--libraries/libVilistextum/main.c (renamed from libraries/libVilistextum/vilistextum_main.c)0
-rw-r--r--libraries/libVilistextum/meson.build15
-rw-r--r--libraries/libVilistextum/test.c85
4 files changed, 103 insertions, 2 deletions
diff --git a/libraries/libVilistextum/fileio.c b/libraries/libVilistextum/fileio.c
index b82c50f2..637df68b 100644
--- a/libraries/libVilistextum/fileio.c
+++ b/libraries/libVilistextum/fileio.c
@@ -55,6 +55,7 @@ void open_files(char *input)
void output_string(CHAR *str)
{
+ int output_was_empty = currentsize == 0;
currentsize += wcslen(str) + wcslen(LINEBREAK);
if(currentsize > outputsize)
@@ -67,8 +68,10 @@ void output_string(CHAR *str)
OUTPUT = realloc(OUTPUT, sizeof(CHAR)*(outputsize+1));
}
+ if (!output_was_empty){
+ wcscat(OUTPUT, LINEBREAK);
+ }
wcscat(OUTPUT, str);
- wcscat(OUTPUT, LINEBREAK);
}
/* ------------------------------------------------ */
diff --git a/libraries/libVilistextum/vilistextum_main.c b/libraries/libVilistextum/main.c
index 169c7c5b..169c7c5b 100644
--- a/libraries/libVilistextum/vilistextum_main.c
+++ b/libraries/libVilistextum/main.c
diff --git a/libraries/libVilistextum/meson.build b/libraries/libVilistextum/meson.build
index ebb8e46b..09b61963 100644
--- a/libraries/libVilistextum/meson.build
+++ b/libraries/libVilistextum/meson.build
@@ -19,5 +19,18 @@ vilistextum_lib = static_library(
vilistextum_main = executable(
'vilistextum_main',
- 'vilistextum_main.c',
+ 'main.c',
link_with: vilistextum_lib)
+
+vilistextum_test = executable(
+ 'vilistextum_test',
+ 'test.c',
+ link_with: vilistextum_lib,
+ dependencies: [ glib ])
+
+
+if gtester.found()
+ test('Vilistextum', gtester, args:['-k', '-o', meson.build_root() + '/vilistextum.gtester.log', vilistextum_test])
+else
+ test('Vilistextum', vilistextum_test)
+endif
diff --git a/libraries/libVilistextum/test.c b/libraries/libVilistextum/test.c
new file mode 100644
index 00000000..cf138025
--- /dev/null
+++ b/libraries/libVilistextum/test.c
@@ -0,0 +1,85 @@
+#include <glib.h>
+
+#include "vilistextum.h"
+
+static void test_changed_inputs_with_html(void)
+{
+ char* inputs[][2] = {
+ {"<h ", "<h"},
+ {"a\nb", "a b"},
+ {"a<br>b", "a<br>b"},
+ //{"test&nbsp;two", "test\xa0two"},
+ //{"test&#160;two", "test\xa0two"},
+ //{"test&#160two", "test\xa0two"}
+ };
+ for (size_t i = 0; i < sizeof(inputs) / sizeof(char*[2]); ++i)
+ {
+ char* input = inputs[i][0];
+ char* output = vilistextum(input, 0);
+ char* expect = inputs[i][1];
+ g_assert_cmpstr(output, ==, expect);
+ }
+}
+
+static void test_unchanged_inputs_with_html(void)
+{
+ char* inputs[] = {
+ "&",
+ "<",
+ "<h",
+ "<r \xfd\xbd\xbd\xbd\xbd\xbd",
+ "test&nbsptwo"
+ };
+ for (size_t i = 0; i < sizeof(inputs) / sizeof(char*); ++i)
+ {
+ char* input = inputs[i];
+ char* output = vilistextum(input, 0);
+ g_assert_cmpstr(output, ==, input);
+ }
+}
+
+static void test_changed_inputs_without_html(void)
+{
+ char* inputs[][2] = {
+ //{"<h ", "<h"},
+ {"a\nb", "a b"},
+ {"a<br/>b", "a\nb"},
+ //{"test&nbsp;two", "test\xa0two"},
+ //{"test&#160;two", "test\xa0two"},
+ //{"test&#160two", "test\xa0two"}
+ };
+ for (size_t i = 0; i < sizeof(inputs) / sizeof(char*[2]); ++i)
+ {
+ char* input = inputs[i][0];
+ char* output = vilistextum(input, 1);
+ char* expect = inputs[i][1];
+ g_assert_cmpstr(output, ==, expect);
+ }
+}
+
+static void test_unchanged_inputs_without_html(void)
+{
+ char* inputs[] = {
+ "&",
+ "<",
+ //"<h",
+ //"<r \xfd\xbd\xbd\xbd\xbd\xbd",
+ "test&nbsptwo"
+ };
+ for (size_t i = 0; i < sizeof(inputs) / sizeof(char*); ++i)
+ {
+ char* input = inputs[i];
+ char* output = vilistextum(input, 1);
+ g_assert_cmpstr(output, ==, input);
+ }
+}
+
+int main(int argc, char **argv)
+{
+ g_test_init(&argc, &argv, NULL);
+ g_test_add_func("/vilistextum/unchanged-inputs/with-html", test_unchanged_inputs_with_html);
+ g_test_add_func("/vilistextum/changed-inputs/with-html", test_changed_inputs_with_html);
+ g_test_add_func("/vilistextum/unchanged-inputs/text-only", test_unchanged_inputs_without_html);
+ g_test_add_func("/vilistextum/changed-inputs/text-only", test_changed_inputs_without_html);
+ return g_test_run();
+}