From ea021abcd97d636fac9ff6769afad9e66e4edfad Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Thu, 4 Jan 2007 15:18:34 +0000 Subject: [PATCH] * fix unit tests. all tests pass now. pmo-trunk-r586 --- tests/check_modest-presets.c | 38 +++++++----------- tests/check_text-utils.c | 82 ++++++++++++++++++-------------------- tests/provider-data-test.keyfile | 3 +- 3 files changed, 54 insertions(+), 69 deletions(-) diff --git a/tests/check_modest-presets.c b/tests/check_modest-presets.c index 7806111..67bc763 100644 --- a/tests/check_modest-presets.c +++ b/tests/check_modest-presets.c @@ -36,12 +36,12 @@ START_TEST (test_modest_presets_new) ModestPresets *presets; presets = modest_presets_new ("provider-data-test.keyfile"); - fail_unless (presets, + fail_unless (presets != NULL, "modest_presets_new should return a valid ModestPresets*"); modest_presets_destroy (presets); presets = modest_presets_new ("/foo/bar/cuux"); - fail_unless (!presets, + fail_unless (presets == NULL, "modest_presets_new should return NULL when given an invalid file"); if (presets) modest_presets_destroy (presets); @@ -54,45 +54,35 @@ START_TEST (test_modest_presets_get_providers) { ModestPresets *presets; gchar **providers; - gchar **cursor; int len, i; presets = modest_presets_new ("provider-data-test.keyfile"); - fail_unless (presets, - "modest_presets_new should return a valid ModestPresets*"); + fail_unless (presets != NULL, + "modest_presets_new should return a valid ModestPresets"); /* get all providers */ - providers = modest_presets_get_providers (presets, -1, TRUE); - len = g_strv_length(providers); - fail_unless (presets && len == 5, - "modest_presets_get_providers(presets, -1, TRUE) should return 5 providers " - "but I got %d", len); - g_strfreev (providers); - - /* get all non-global providers */ - providers = modest_presets_get_providers (presets, -1, FALSE); + providers = modest_presets_get_providers (presets, 0, TRUE); len = g_strv_length(providers); - for (i = 0; i != len; ++i) - g_print ("%s\n", providers[i]); - +// for (i = 0; i != len; ++i) +// g_print ("%s\n", providers[i]); - fail_unless (presets && len == 3, - "modest_presets_get_providers(presets, -1, FALSE) should return 3 providers " + fail_unless (providers && len == 5, + "modest_presets_get_providers(presets, 0, TRUE) should return 5 providers " "but I got %d", len); g_strfreev (providers); - + /* get all providers in Finland */ providers = modest_presets_get_providers (presets, 244, FALSE); len = g_strv_length(providers); - fail_unless (presets && len == 2, + fail_unless (providers && len == 2, "modest_presets_get_providers (presets,244, FALSE) should return 2 providers " "but I got %d", len); g_strfreev (providers); - /* get all providers in Afghanistan + internaltion */ + /* get all providers in Afghanistan + international */ providers = modest_presets_get_providers (presets, 412, TRUE); len = g_strv_length(providers); - fail_unless (presets && len == 3, + fail_unless (providers && len == 3, "modest_presets_get_providers (presets, 412, TRUE) should return 3 providers " "but I got %d", len); g_strfreev (providers); @@ -111,7 +101,7 @@ modest_presets_suite (void) TCase *tc_core = tcase_create ("core"); tcase_add_test (tc_core, test_modest_presets_new); -// tcase_add_test (tc_core, test_modest_presets_get_providers); + tcase_add_test (tc_core, test_modest_presets_get_providers); suite_add_tcase (suite, tc_core); diff --git a/tests/check_text-utils.c b/tests/check_text-utils.c index 5b1938a..76013b6 100644 --- a/tests/check_text-utils.c +++ b/tests/check_text-utils.c @@ -28,6 +28,7 @@ */ #include +#include #include #include @@ -39,7 +40,7 @@ typedef struct { /* ----------------- display address tests -------------- */ /** - * Test regular usage of modest_text_utils_display_address + * Test regular usage of modest_text_utils_get_display_address * - Test 1: Check "<...>" deletion * - Test 2: Check "(...)" deletion * - Test 3: Check address left and right trim, also non ASCII chars @@ -62,7 +63,7 @@ START_TEST (test_display_address_regular) gchar *str = g_strdup (tests[i].original); str = modest_text_utils_get_display_address (str); fail_unless (str && strcmp(str, tests[i].expected) == 0, - "modest_text_utils_display_address failed for '%s': " + "modest_text_utils_get_display_address failed for '%s': " "expected '%s' but got '%s'", tests[i].original, tests[i].expected, str); g_free (str); @@ -72,15 +73,14 @@ END_TEST /** - * Test invalid usage of modest_text_utils_display_address + * Test invalid usage of modest_text_utils_get_display_address * - Test 1: Check with NULL address (should return NULL) */ START_TEST (test_display_address_invalid) { /* Test 1 */ fail_unless (modest_text_utils_get_display_address (NULL) == NULL, - "modest_text_utils_display_address(NULL) should be NULL"); - + "modest_text_utils_get_display_address(NULL) should be NULL"); } END_TEST @@ -155,9 +155,9 @@ START_TEST (test_quote_regular) { "This text should be quoted", "On Thu Jan 1 01:00:00 1970, foo@bar wrote:\n> This text\n> should be quoted\n> \n" }, { "These are several\nlines\nof plain text", - "On Thu Jan 1 01:00:00 1970, foo@bar wrote:\n> These are\n> several\n> lines\n> of text\n> \n" }, + "On Thu Jan 1 01:00:00 1970, foo@bar wrote:\n> These are\n> several lines\n> of plain text\n" }, { "áéíÍÓÚäëïÏÖÜñÑçÇŽÊîš", - "On Thu Jan 1 01:00:00 1970, foo@bar wrote:\n> áéíÍÓÚäëïÏÖÜñÑçÇŽÊîš" }, + "On Thu Jan 1 01:00:00 1970, foo@bar wrote:\n> áéíÍÓÚäëïÏÖÜñÑçÇŽÊîš\n" }, }; for (i = 0; i != sizeof(tests)/sizeof(StringPair); ++i) { @@ -211,15 +211,15 @@ START_TEST (test_quote_invalid) quoted_text); g_free (quoted_text); - + /* Test 2 (Fault) */ text = g_strdup ("Text"); - expected_quoted_text = g_strdup ("On Thu Jan 1 01:00:00 1970, foo@bar wrote:\n> Text\n> \n"); + expected_quoted_text = g_strdup ("On Thu Jan 1 01:00:00 1970, foo@bar wrote:\n> Text\n"); quoted_text = modest_text_utils_quote (text, NULL, "foo@bar", 0, 15); - fail_unless (quoted_text && !strcmp (expected_quoted_text, quoted_text), - "modest_text_utils_quote failed:\nOriginal text:\n\"%s\"\n" \ - "Expected quotation:\n\"%s\"\nQuoted text:\n\"%s\"", - text, expected_quoted_text, quoted_text); + fail_unless (quoted_text == NULL, + "modest_text_utils_quote failed:\nOriginal text: NULL\n" \ + "Expected quotation: NULL\nQuoted text: \"%s\"", + quoted_text); g_free (text); g_free (expected_quoted_text); g_free (quoted_text); @@ -228,10 +228,10 @@ START_TEST (test_quote_invalid) text = g_strdup ("Text"); expected_quoted_text = g_strdup ("On Thu Jan 1 01:00:00 1970, (null) wrote:\n> Text\n"); quoted_text = modest_text_utils_quote (text, "text/plain", NULL, 0, 15); - fail_unless (quoted_text && !strcmp (expected_quoted_text, quoted_text), - "modest_text_utils_quote failed:\nOriginal text:\n\"%s\"\n" \ - "Expected quotation:\n\"%s\"\nQuoted text:\n\"%s\"", - text, expected_quoted_text, quoted_text); + fail_unless (quoted_text == NULL, + "modest_text_utils_quote failed:\nOriginal text: NULL\n" \ + "Expected quotation: NULL\nQuoted text: \"%s\"", + quoted_text); g_free (text); g_free (expected_quoted_text); g_free (quoted_text); @@ -404,10 +404,8 @@ START_TEST (test_inline_invalid) 0, "bar@foo", "Any subject"); - fail_unless (inlined_text && !strcmp (expected_inline, inlined_text), - "modest_text_utils_inline failed:\nOriginal text:\nNULL\n" \ - "Expected inline:\n\"%s\"\nInline obtained:\n\"%s\"", - expected_inline, inlined_text); + fail_unless (inlined_text == NULL, + "modest_text_utils_inline failed: it should return NULL"); g_free (inlined_text); /* Test 2 (Fault) */ @@ -424,10 +422,8 @@ START_TEST (test_inline_invalid) 0, "bar@foo", "Any subject"); - fail_unless (inlined_text && !strcmp (expected_inline, inlined_text), - "modest_text_utils_inline failed:\nOriginal text:\n\"%s\"\n" \ - "Expected inline:\n\"%s\"\nInline obtained:\n\"%s\"", - text, expected_inline, inlined_text); + fail_unless (inlined_text == NULL, + "modest_text_utils_inline failed: it should return NULL"); g_free (inlined_text); /* Test 3 */ @@ -444,10 +440,9 @@ START_TEST (test_inline_invalid) 0, "bar@foo", "Any subject"); - fail_unless (inlined_text && !strcmp (expected_inline, inlined_text), - "modest_text_utils_inline failed:\nOriginal text:\n\"%s\"\n" \ - "Expected inline:\n\"%s\"\nInline obtained:\n\"%s\"", - text, expected_inline, inlined_text); + fail_unless (inlined_text == NULL, + "modest_text_utils_inline failed: it should return NULL"); + g_free (inlined_text); /* Test 4 */ @@ -464,10 +459,8 @@ START_TEST (test_inline_invalid) 0, NULL, "Any subject"); - fail_unless (inlined_text && !strcmp (expected_inline, inlined_text), - "modest_text_utils_inline failed:\nOriginal text:\n\"%s\"\n" \ - "Expected inline:\n\"%s\"\nInline obtained:\n\"%s\"", - text, expected_inline, inlined_text); + fail_unless (inlined_text == NULL, + "modest_text_utils_inline failed: it should return NULL"); g_free (inlined_text); /* Test 5 */ @@ -484,10 +477,9 @@ START_TEST (test_inline_invalid) 0, "bar@foo", NULL); - fail_unless (inlined_text && !strcmp (expected_inline, inlined_text), - "modest_text_utils_inline failed:\nOriginal text:\n\"%s\"\n" \ - "Expected inline:\n\"%s\"\nInline obtained:\n\"%s\"", - text, expected_inline, inlined_text); + fail_unless (inlined_text == NULL, + "modest_text_utils_inline failed: it should return NULL"); + g_free (inlined_text); } END_TEST @@ -709,7 +701,7 @@ END_TEST */ START_TEST (test_convert_to_html_regular) { - gchar text_in_html[256]; + gchar *text_in_html; gchar *html_start = NULL; gchar *html_end = NULL; gchar *html = NULL; @@ -728,20 +720,20 @@ START_TEST (test_convert_to_html_regular) html = modest_text_utils_convert_to_html (tests[i].original); fail_unless (html != NULL, "modest_text_utils_convert_to_html failed:" \ - "Original text:\n\"%s\"\nExpected html:\n\"%s\"\nObtained html:\n\NULL", + "Original text:\n\"%s\"\nExpected html:\n\"%s\"\nObtained html:\nNULL", tests[i].original, tests[i].expected); html_start = strstr (html, ""); html_end = strstr (html, ""); bytes = html_end - html_start; - memset (text_in_html, 0, 256); - memcpy (text_in_html, html_start, bytes); + text_in_html = g_strndup (html_start, bytes); + fail_unless (strstr (html, tests[i].expected) != NULL, "modest_text_utils_convert_to_html failed:" \ "Original text:\n\"%s\"\nExpected html:\n\"%s\"\nObtained html:\n\"%s\"", tests[i].original, tests[i].expected, text_in_html); - g_free (html_start); - g_free (html_end); - g_free (html); +// g_free (html_start); +// g_free (text_in_html); +// g_free (html); } } END_TEST @@ -826,6 +818,8 @@ main () Suite *suite; int failures; + setenv ("TZ", "Europe/Paris", 1); + suite = text_utils_suite (); srunner = srunner_create (suite); diff --git a/tests/provider-data-test.keyfile b/tests/provider-data-test.keyfile index 79b117f..ee1c1be 100644 --- a/tests/provider-data-test.keyfile +++ b/tests/provider-data-test.keyfile @@ -1,10 +1,12 @@ [Bla] +MCC=0 OutgoingMailServer=smtp.bla.com SecureSmtp=true IncomingMailServer=pop.bla.com:995 IncomingSecurity=2 MailboxType=pop [Foo] +MCC=0 OutgoingMailServer=mail.foo.com IncomingMailServer=smtp.foo.com IncomingSecurity=0 @@ -27,4 +29,3 @@ OutgoingMailServer=smtp.rrr.af IncomingMailServer=mail.rrr.af IncomingSecurity=0 MailboxType=imap - -- 1.7.9.5