1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <modest-text-utils.h>
37 const gchar *original;
38 const gchar *expected;
41 /* ----------------- display address tests -------------- */
44 * Test regular usage of modest_text_utils_get_display_address
45 * - Test 1: Check "<...>" deletion
46 * - Test 2: Check "(...)" deletion
47 * - Test 3: Check address left and right trim, also non ASCII chars
48 * - Test 4: Check issues in tests 1, 2 and 3 together
49 * - Test 5: Check with an empty address
51 START_TEST (test_get_display_address_regular)
54 const StringPair tests[] = {
55 { "John Doe <foo@bar>", "John Doe" },
56 { "Rupert Griffin (test)", "Rupert Griffin"},
57 { " Hyvää päivää ", "Hyvää päivää"},
58 { " John Doe <foo@bar> (test) ", "John Doe" },
62 /* Tests 1, 2, 3, 4 */
63 for (i = 0; i != sizeof(tests)/sizeof(StringPair); ++i) {
64 gchar *str = g_strdup (tests[i].original);
65 str = modest_text_utils_get_display_address (str);
66 fail_unless (str && strcmp(str, tests[i].expected) == 0,
67 "modest_text_utils_get_display_address failed for '%s': "
68 "expected '%s' but got '%s'",
69 tests[i].original, tests[i].expected, str);
77 * Test invalid usage of modest_text_utils_get_display_address
78 * - Test 1: Check with NULL address (should return NULL)
80 START_TEST (test_get_display_address_invalid)
83 fail_unless (modest_text_utils_get_display_address (NULL) == NULL,
84 "modest_text_utils_get_display_address(NULL) should be NULL");
88 /* ----------------- derived address tests -------------- */
91 * Test regular usage of modest_text_utils_derived_subject
92 * - Test 1: Check with a normal subject
93 * - Test 2: Test with NULL subject
94 * - Test 3: Test with non ASCII chars
95 * - Test 4: Test with an empty subject
97 START_TEST (test_derived_subject_regular)
100 const gchar *prefix="Re:";
101 const StringPair tests[] = {
102 { "subject", "Re: subject" },
104 { "Hyvää päivää", "Re: Hyvää päivää"},
108 /* Tests 1, 2, 3, 4 */
109 for (i = 0; i != sizeof(tests)/sizeof(StringPair); ++i) {
110 gchar *orig = g_strdup (tests[i].original);
111 gchar *str = modest_text_utils_derived_subject (orig, prefix);
112 fail_unless (str && strcmp(str, tests[i].expected) == 0,
113 "modest_text_utils_derived_subject failed for '%s': "
114 "expected '%s' but got '%s'",
115 tests[i].original, tests[i].expected, str);
123 * Test invalid usage of modest_text_utils_derived_subject
124 * - Test 1: Check with NULL prefix (should return NULL)
126 START_TEST (test_derived_subject_invalid)
129 fail_unless (modest_text_utils_derived_subject (NULL, NULL) == NULL,
130 "modest_text_utils_derived_subject (*,NULL) should be NULL");
134 /* --------------------- quote tests -------------------- */
137 * Test regular usage of modest_text_utils_quote
138 * - Test 1: Quote empty text
139 * - Test 2: Quote 1 line of plain text
140 * - Test 3: Quote several lines of plain text
141 * - Test 4: Quote non ASCII chars
142 * - Test 5: Quote with a limit lower than the any word in the text
143 * - TODO: Test HTML quotation once its implementation if finished
145 START_TEST (test_quote_regular)
149 gchar *expected_quoted_text = NULL;
150 gchar *quoted_text = NULL;
153 const StringPair tests[] = {
155 "On Thu Jan 1 01:00:00 1970, foo@bar wrote:\n> \n" },
156 { "This text should be quoted",
157 "On Thu Jan 1 01:00:00 1970, foo@bar wrote:\n> This text\n> should be quoted\n> \n" },
158 { "These are several\nlines\nof plain text",
159 "On Thu Jan 1 01:00:00 1970, foo@bar wrote:\n> These are\n> several lines\n> of plain text\n" },
160 { "áéíÍÓÚäëïÏÖÜñÑçÇŽÊîš",
161 "On Thu Jan 1 01:00:00 1970, foo@bar wrote:\n> áéíÍÓÚäëïÏÖÜñÑçÇŽÊîš\n" },
164 for (i = 0; i != sizeof(tests)/sizeof(StringPair); ++i) {
165 text = g_strdup (tests[i].original);
166 expected_quoted_text = g_strdup (tests[i].expected);
167 quoted_text = modest_text_utils_quote (text, "text/plain", "foo@bar", 0, 15);
168 fail_unless (quoted_text && strcmp(expected_quoted_text, quoted_text)==0,
169 "modest_text_utils_quote failed:\nOriginal text:\n\"%s\"\n" \
170 "Expected quotation:\n\"%s\"\nQuoted text:\n\"%s\"",
171 text, expected_quoted_text, quoted_text);
173 g_free (expected_quoted_text);
174 g_free (quoted_text);
178 text = g_strdup ("Quotation test example");
179 expected_quoted_text =
180 g_strdup ("On Thu Jan 1 01:00:00 1970, foo@bar wrote:\n> Quotation\n> test\n> example\n> \n");
181 quoted_text = modest_text_utils_quote (text, "text/plain", "foo@bar", 0, 1);
182 fail_unless (quoted_text && !strcmp (expected_quoted_text, quoted_text),
183 "modest_text_utils_quote failed:\nOriginal text:\n\"%s\"\n" \
184 "Expected quotation:\n\"%s\"\nQuoted text:\n\"%s\"",
185 text, expected_quoted_text, quoted_text);
187 g_free (expected_quoted_text);
188 g_free (quoted_text);
193 * Test invalid usage of modest_text_utils_quote
194 * - Test 1: Check NULL text (should return NULL)
195 * - Test 2: Check NULL content_type (should quote as text/plain)
196 * - Test 3: Check NULL address (should cite address as "(null)")
197 * - Test 4: Check negative limit (should write each word in its own line)
198 * - TODO: Repeat tests for HTML quotation when its implementation is finished
200 START_TEST (test_quote_invalid)
203 gchar *expected_quoted_text = NULL;
204 gchar *quoted_text = NULL;
208 quoted_text = modest_text_utils_quote (NULL, "text/plain", "foo@bar", 0, 15);
209 fail_unless (quoted_text == NULL,
210 "modest_text_utils_quote failed:\nOriginal text: NULL\n" \
211 "Expected quotation: NULL\nQuoted text: \"%s\"",
213 g_free (quoted_text);
217 text = g_strdup ("Text");
218 expected_quoted_text = g_strdup ("On Thu Jan 1 01:00:00 1970, foo@bar wrote:\n> Text\n");
219 quoted_text = modest_text_utils_quote (text, NULL, "foo@bar", 0, 15);
220 fail_unless (quoted_text == NULL,
221 "modest_text_utils_quote failed:\nOriginal text: NULL\n" \
222 "Expected quotation: NULL\nQuoted text: \"%s\"",
225 g_free (expected_quoted_text);
226 g_free (quoted_text);
229 text = g_strdup ("Text");
230 expected_quoted_text = g_strdup ("On Thu Jan 1 01:00:00 1970, (null) wrote:\n> Text\n");
231 quoted_text = modest_text_utils_quote (text, "text/plain", NULL, 0, 15);
232 fail_unless (quoted_text == NULL,
233 "modest_text_utils_quote failed:\nOriginal text: NULL\n" \
234 "Expected quotation: NULL\nQuoted text: \"%s\"",
237 g_free (expected_quoted_text);
238 g_free (quoted_text);
241 text = g_strdup ("This is a text");
242 expected_quoted_text = g_strdup ("On Thu Jan 1 01:00:00 1970, foo@bar wrote:\n> This\n> is\n> a\n> text\n> \n");
243 quoted_text = modest_text_utils_quote (text, "text/plain", "foo@bar", 0, 0);
244 fail_unless (quoted_text && !strcmp (expected_quoted_text, quoted_text),
245 "modest_text_utils_quote failed:\nOriginal text:\n\"%s\"\n" \
246 "Expected quotation:\n\"%s\"\nQuoted text:\n\"%s\"",
247 text, expected_quoted_text, quoted_text);
249 g_free (expected_quoted_text);
250 g_free (quoted_text);
254 /* ---------------------- cite tests -------------------- */
257 * Test regular usage of modest_text_utils_cite
258 * - Test 1: Check cite of an empty text
259 * - Test 2: Check cite of a line of text
260 * - Test 3: Check cite of several lines of text
261 * - Test 4: Check with non ASCII chars
263 START_TEST (test_cite_regular)
266 gchar *cited_text = NULL;
267 const StringPair tests[] = {
269 "On Thu Jan 1 01:00:00 1970, foo@bar wrote:\n\n" },
270 { "This is some text",
271 "On Thu Jan 1 01:00:00 1970, foo@bar wrote:\nThis is some text\n" },
272 { "This\nis some\ntext",
273 "On Thu Jan 1 01:00:00 1970, foo@bar wrote:\nThis\nis some\ntext\n" },
274 { "áéíÍÓÚäëïÏÖÜñÑçÇŽÊîš",
275 "On Thu Jan 1 01:00:00 1970, foo@bar wrote:\náéíÍÓÚäëïÏÖÜñÑçÇŽÊîš\n" },
278 /* Tests 1, 2, 3, 4 */
279 for (i = 0; i != sizeof(tests)/sizeof(StringPair); ++i) {
280 cited_text = modest_text_utils_cite (tests[i].original, "text/plain", "foo@bar", 0);
281 fail_unless (cited_text && !strcmp (tests[i].expected, cited_text),
282 "modest_text_utils_cite failed:\nOriginal text:\n\"%s\"\n" \
283 "Expected cite:\n\"%s\"\nCite obtained:\n\"%s\"",
284 tests[i].original, tests[i].expected, cited_text);
291 * Test invalid usage of modest_text_utils_cite
292 * - Test 1: Check NULL text (should cite text as (null))
293 * - Test 2: Check NULL address (should cite address as (null)
294 * TODO: add tests for content_type once it is used in the implementation
296 START_TEST (test_cite_invalid)
299 gchar *cited_text = NULL;
300 gchar *expected_cite = NULL;
304 expected_cite = g_strdup ("On Thu Jan 1 01:00:00 1970, foo@bar wrote:\n(null)\n");
305 cited_text = modest_text_utils_cite (text, "text/plain", "foo@bar", 0);
306 fail_unless (cited_text && !strcmp (expected_cite, cited_text),
307 "modest_text_utils_cite failed:\nOriginal text:\nNULL\n" \
308 "Expected cite:\n\"%s\"\nCite obtained:\n\"%s\"",
309 expected_cite, cited_text);
310 g_free (expected_cite);
314 text = g_strdup ("This is some text");
315 expected_cite = g_strdup ("On Thu Jan 1 01:00:00 1970, (null) wrote:\nThis is some text\n");
316 cited_text = modest_text_utils_cite (text, "text/plain", NULL, 0);
317 fail_unless (cited_text && !strcmp (expected_cite, cited_text),
318 "modest_text_utils_cite failed:\nOriginal text:\n\"%s\"\n" \
319 "Expected cite:\n\"%s\"\nCite obtained:\n\"%s\"",
320 text, expected_cite, cited_text);
322 g_free (expected_cite);
327 /* -------------------- inline tests -------------------- */
330 * Test regular usage of modest_text_utils_inline
331 * - Test 1: Check inline of an empty text
332 * - Test 2: Check inline of a regular text
333 * - Test 3: Check with non ASCII chars
334 * TODO: add tests for HTML when implementation is finished
336 START_TEST (test_inline_regular)
339 gchar *inlined_text = NULL;
340 const StringPair tests[] = {
342 "-----Forwarded Message-----\n" \
344 "Sent: Thu Jan 1 01:00:00 1970\n" \
346 "Subject: Any subject\n\n" },
347 { "Some text\nto inline",
348 "-----Forwarded Message-----\n" \
350 "Sent: Thu Jan 1 01:00:00 1970\n" \
352 "Subject: Any subject\n\n" \
353 "Some text\nto inline" },
354 { "áéíÍÓÚäëïÏÖÜñÑçÇŽÊîš",
355 "-----Forwarded Message-----\n" \
357 "Sent: Thu Jan 1 01:00:00 1970\n" \
359 "Subject: Any subject\n\n" \
360 "áéíÍÓÚäëïÏÖÜñÑçÇŽÊîš" },
364 for (i = 0; i != sizeof(tests)/sizeof(StringPair); ++i) {
365 inlined_text = modest_text_utils_inline (tests[i].original,
371 fail_unless (inlined_text && !strcmp (tests[i].expected, inlined_text),
372 "modest_text_utils_inline failed:\nOriginal text:\n\"%s\"\n" \
373 "Expected inline:\n\"%s\"\nInline obtained:\n\"%s\"",
374 tests[i].original, tests[i].expected, inlined_text);
375 g_free (inlined_text);
381 * Test invalid usage of modest_text_utils_inline
382 * - Test 1: Check NULL text (should inline text as (null))
383 * - Test 2: Check NULL content_type (should assume text/plain)
384 * - Test 3: Check NULL from (should write "(null)")
385 * - Test 4: Check NULL to (should write ("null"))
386 * - Test 5: Check NULL subject (should write ("null"))
387 * TODO: repeat tests from HTML when implemented
389 START_TEST (test_inline_invalid)
392 gchar *expected_inline = NULL;
393 gchar *inlined_text = NULL;
396 expected_inline = g_strdup("-----Forwarded Message-----\n" \
398 "Sent: Thu Jan 1 01:00:00 1970\n" \
400 "Subject: Any subject\n\n" \
402 inlined_text = modest_text_utils_inline (NULL,
408 fail_unless (inlined_text == NULL,
409 "modest_text_utils_inline failed: it should return NULL");
410 g_free (inlined_text);
413 text = g_strdup ("Some text");
414 expected_inline = g_strdup("-----Forwarded Message-----\n" \
416 "Sent: Thu Jan 1 01:00:00 1970\n" \
418 "Subject: Any subject\n\n" \
420 inlined_text = modest_text_utils_inline (text,
426 fail_unless (inlined_text == NULL,
427 "modest_text_utils_inline failed: it should return NULL");
428 g_free (inlined_text);
431 text = g_strdup ("Some text");
432 expected_inline = g_strdup("-----Forwarded Message-----\n" \
434 "Sent: Thu Jan 1 01:00:00 1970\n" \
436 "Subject: Any subject\n\n" \
438 inlined_text = modest_text_utils_inline (text,
444 fail_unless (inlined_text == NULL,
445 "modest_text_utils_inline failed: it should return NULL");
447 g_free (inlined_text);
450 text = g_strdup ("Some text");
451 expected_inline = g_strdup("-----Forwarded Message-----\n" \
453 "Sent: Thu Jan 1 01:00:00 1970\n" \
455 "Subject: Any subject\n\n" \
457 inlined_text = modest_text_utils_inline (text,
463 fail_unless (inlined_text == NULL,
464 "modest_text_utils_inline failed: it should return NULL");
465 g_free (inlined_text);
468 text = g_strdup ("Some text");
469 expected_inline = g_strdup("-----Forwarded Message-----\n" \
471 "Sent: Thu Jan 1 01:00:00 1970\n" \
473 "Subject: (null)\n\n" \
475 inlined_text = modest_text_utils_inline (text,
481 fail_unless (inlined_text == NULL,
482 "modest_text_utils_inline failed: it should return NULL");
484 g_free (inlined_text);
488 /* ---------------- remove address tests ---------------- */
491 * Test regular usage of modest_text_utils_remove_address
492 * - Test 1: Remove a single address in the middle of a list
493 * - Test 2: Remove an extended address in the middle of a list
494 * - Test 3: Remove an address that appears more than once in the list
495 * - Test 4: Remove address from an empty list
496 * - Test 5: Check with non ASCII characters
498 START_TEST (test_remove_address_regular)
501 gchar *new_list = NULL;
502 gchar *address = NULL;
505 list = g_strdup ("foo@bar <foo>, myname@mycompany.com (myname), " \
506 "xxx@yyy.zzz (xxx yyy zzz), bar@foo");
507 address = g_strdup ("xxx@yyy.zzz");
508 new_list = modest_text_utils_remove_address (list, address);
510 fail_unless (new_list && strstr (new_list, "foo@bar <foo>") != NULL,
511 "modest_text_utils_remove_address failed: "\
512 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
513 address, list, new_list);
514 fail_unless (new_list && strstr (new_list, "myname@mycompany.com (myname)") != NULL,
515 "modest_text_utils_remove_address failed: " \
516 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
517 address, list, new_list);
518 fail_unless (new_list && strstr (new_list, "bar@foo") != NULL,
519 "modest_text_utils_remove_address failed: " \
520 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
521 address, list, new_list);
522 fail_unless (new_list && strstr (new_list, "xxx@yyy.zzz") == NULL,
523 "modest_text_utils_remove_address failed: " \
524 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
525 address, list, new_list);
526 fail_unless (new_list && strstr (new_list, "(xxx yyy zzz)") == NULL,
527 "modest_text_utils_remove_address failed: " \
528 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
529 address, list, new_list);
536 list = g_strdup ("foo@bar <foo>, xxx@yyy.zzz (xxx yyy zzz), bar@foo");
537 address = g_strdup ("xxx@yyy.zzz (xxx yyy zzz)");
538 new_list = modest_text_utils_remove_address (list, address);
540 fail_unless (new_list && strstr (new_list, "foo@bar <foo>") != NULL,
541 "modest_text_utils_remove_address failed: " \
542 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
543 address, list, new_list);
544 fail_unless (new_list && strstr (new_list, "bar@foo") != NULL,
545 "modest_text_utils_remove_address failed: " \
546 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
547 address, list, new_list);
548 fail_unless (new_list && strstr (new_list, "xxx@yyy.zzz") == NULL,
549 "modest_text_utils_remove_address failed: " \
550 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
551 address, list, new_list);
552 fail_unless (new_list && strstr (new_list, "(xxx yyy zzz)") == NULL,
553 "modest_text_utils_remove_address failed: " \
554 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
555 address, list, new_list);
562 list = g_strdup ("foo@bar <foo>, bar@foo (BAR), xxx@yyy.zzz (xxx yyy zzz), bar@foo");
563 address = g_strdup ("bar@foo");
564 new_list = modest_text_utils_remove_address (list, address);
566 fail_unless (new_list && strstr (new_list, "foo@bar <foo>") != NULL,
567 "modest_text_utils_remove_address failed: " \
568 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
569 address, list, new_list);
570 fail_unless (new_list && strstr (new_list, "xxx@yyy.zzz (xxx yyy zzz)") != NULL,
571 "modest_text_utils_remove_address failed: " \
572 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
573 address, list, new_list);
574 fail_unless (new_list && strstr (new_list, "bar@foo") == NULL,
575 "modest_text_utils_remove_address failed: " \
576 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
577 address, list, new_list);
578 fail_unless (new_list && strstr (new_list, "(BAR)") == NULL,
579 "modest_text_utils_remove_address failed: " \
580 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
581 address, list, new_list);
588 list = g_strdup ("");
589 address = g_strdup ("bar@foo");
590 new_list = modest_text_utils_remove_address (list, address);
592 fail_unless (new_list && !strcmp (new_list, list),
593 "modest_text_utils_remove_address failed: " \
594 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
595 address, list, new_list);
602 list = g_strdup ("foo@bar, áñï@Èž.com (Àç ÑŸž), bar@foo");
603 address = g_strdup ("áñï@Èž.com");
604 new_list = modest_text_utils_remove_address (list, address);
606 fail_unless (new_list && strstr (new_list, "foo@bar") != NULL,
607 "modest_text_utils_remove_address failed: " \
608 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
609 address, list, new_list);
610 fail_unless (new_list && strstr (new_list, "bar@foo") != NULL,
611 "modest_text_utils_remove_address failed: " \
612 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
613 address, list, new_list);
614 fail_unless (new_list && strstr (new_list, "áñï@Èž.com") == NULL,
615 "modest_text_utils_remove_address failed: " \
616 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
617 address, list, new_list);
618 fail_unless (new_list && strstr (new_list, "(Àç ÑŸž)") == NULL,
619 "modest_text_utils_remove_address failed: " \
620 "Removing \"%s\" from address list \"%s\" returns \"%s\"",
621 address, list, new_list);
630 * Test limits usage of modest_text_utils_remove_address
631 * - Test 1: Remove address at the beginning of the list
632 * - Test 2: Remove address at the end of the list
633 * - Test 3: Remove the address of a one-element-size list
635 START_TEST (test_remove_address_limits)
638 gchar *new_list = NULL;
639 gchar *expected_list = NULL;
640 //gchar *address = NULL;
643 const StringPair tests[] = {
644 { "foo@bar <FOO BAR>, bar@foo (BAR FOO)", "bar@foo (BAR FOO)" },
645 { "foo@bar <FOO BAR>, bar@foo (BAR FOO)", "foo@bar <FOO BAR>" },
646 { "foo@bar <FOO BAR>", "" },
648 const gchar *remove[] = { "foo@bar", "bar@foo", "foo@bar" };
651 for (i = 0; i != sizeof(tests)/sizeof(StringPair); ++i) {
652 list = g_strdup (tests[i].original);
653 expected_list = g_strdup (tests[i].expected);
654 new_list = modest_text_utils_remove_address (list, remove[i]);
655 fail_unless (new_list && !strcmp (expected_list, new_list),
656 "modest_text_utils_remove_address failed: " \
657 "Removing \"%s\" from address list \"%s\" returns \"%s\" instead of \"%s\"",
658 remove[i], list, new_list, expected_list);
660 g_free (expected_list);
667 * Test invalid usage of modest_text_utils_remove_address
668 * - Test 1: Remove a NULL address (should return the same list)
669 * - Test 2: Remove an address form a NULL list (should return NULL)
671 START_TEST (test_remove_address_invalid)
674 gchar *new_list = NULL;
677 list = g_strdup ("foo@bar, bar@foo");
678 new_list = modest_text_utils_remove_address (list, NULL);
679 fail_unless (new_list && !strcmp (list, new_list),
680 "modest_text_utils_remove_address failed: " \
681 "Removing a NULL address from \"%s\" returns \"%s\"",
687 new_list = modest_text_utils_remove_address (NULL, "foo@bar");
688 fail_unless (new_list == NULL,
689 "modest_text_utils_remove_address failed: " \
690 "Removing an address from a NULL list does not return NULL");
695 /* --------------- convert to html tests ---------------- */
698 * Test regular usage of modest_text_utils_convert_to_html
699 * - Test 1: Check conversion of a regular text
700 * - Test 2: Check conversion of a regular text with links
701 * - Test 3: Check conversion of a regular text with special html chars
703 START_TEST (test_convert_to_html_regular)
706 gchar *html_start = NULL;
707 gchar *html_end = NULL;
712 const StringPair tests[] = {
713 { "This is some text.",
714 "<tt>This is some text.</tt>" },
715 { "http://xxx.yyy.zzz/myfile",
716 "<tt><a href=\"http://xxx.yyy.zzz/myfile\">http://xxx.yyy.zzz/myfile</a></tt>" },
718 "<tt><a " b><br>\n x</tt>" },
722 for (i = 0; i != sizeof(tests)/sizeof(StringPair); ++i) {
723 html = modest_text_utils_convert_to_html (tests[i].original);
724 fail_unless (html != NULL,
725 "modest_text_utils_convert_to_html failed:" \
726 "Original text:\n\"%s\"\nExpected html:\n\"%s\"\nObtained html:\nNULL",
727 tests[i].original, tests[i].expected);
728 html_start = strstr (html, "<tt>");
729 html_end = strstr (html, "</body>");
730 bytes = html_end - html_start;
731 text_in_html = g_strndup (html_start, bytes);
733 fail_unless (strstr (html, tests[i].expected) != NULL,
734 "modest_text_utils_convert_to_html failed:" \
735 "Original text:\n\"%s\"\nExpected html:\n\"%s\"\nObtained html:\n\"%s\"",
736 tests[i].original, tests[i].expected, text_in_html);
737 // g_free (html_start);
738 // g_free (text_in_html);
745 * Test invalid usage of modest_text_utils_convert_to_html
746 * - Test 1: Check with NULL data
748 START_TEST (test_convert_to_html_invalid)
753 html = modest_text_utils_convert_to_html (NULL);
754 fail_unless (html == NULL,
755 "modest_text_utils_convert_to_html failed:" \
756 "Does not return NULL when passed NULL data");
761 /* ------------------- Suite creation ------------------- */
764 text_utils_suite (void)
766 Suite *suite = suite_create ("ModestTextUtils");
769 /* Tests case for "display adress" */
770 tc = tcase_create ("display_adress");
771 tcase_add_test (tc, test_get_display_address_regular);
772 tcase_add_test (tc, test_get_display_address_invalid);
773 suite_add_tcase (suite, tc);
775 /* Test case for "derived subject" */
776 tc = tcase_create ("derived_subject");
777 tcase_add_test (tc, test_derived_subject_regular);
778 tcase_add_test (tc, test_derived_subject_invalid);
779 suite_add_tcase (suite, tc);
781 /* Test case for "quote" */
782 tc = tcase_create ("quote");
783 tcase_add_test (tc, test_quote_regular);
784 tcase_add_test (tc, test_quote_invalid);
785 suite_add_tcase (suite, tc);
787 /* Test case for "cite" */
788 tc = tcase_create ("cite");
789 tcase_add_test (tc, test_cite_regular);
790 tcase_add_test (tc, test_cite_invalid);
791 suite_add_tcase (suite, tc);
793 /* Test case for "inline" */
794 tc = tcase_create ("inline");
795 tcase_add_test (tc, test_inline_regular);
796 tcase_add_test (tc, test_inline_invalid);
797 suite_add_tcase (suite, tc);
799 /* Test case for "remove address" */
800 tc = tcase_create ("remove_address");
801 tcase_add_test (tc, test_remove_address_regular);
802 tcase_add_test (tc, test_remove_address_limits);
803 tcase_add_test (tc, test_remove_address_invalid);
804 suite_add_tcase (suite, tc);
806 /* Test case for "convert to html" */
807 tc = tcase_create ("convert_to_html");
808 tcase_add_test (tc, test_convert_to_html_regular);
809 tcase_add_test (tc, test_convert_to_html_invalid);
810 suite_add_tcase (suite, tc);
815 /* --------------------- Main program ------------------- */
824 setenv ("TZ", "Europe/Paris", 1);
826 suite = text_utils_suite ();
827 srunner = srunner_create (suite);
829 srunner_run_all (srunner, CK_ENV);
830 failures = srunner_ntests_failed (srunner);
831 srunner_free (srunner);