* updated test case, code cleanup, documentation fixes
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Mon, 11 Dec 2006 16:06:21 +0000 (16:06 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Mon, 11 Dec 2006 16:06:21 +0000 (16:06 +0000)
pmo-trunk-r541

src/modest-text-utils.c
src/modest-text-utils.h
tests/check_text-utils.c

index 0900a69..130bc8f 100644 (file)
@@ -198,8 +198,10 @@ modest_text_utils_derived_subject (const gchar *subject, const gchar *prefix)
 {
        gchar *tmp;
 
+       g_return_val_if_fail (prefix, NULL);
+       
        if (!subject)
-               return g_strdup_printf ("%s ", prefix);
+               return g_strdup (prefix);
 
        tmp = g_strchug (g_strdup (subject));
 
index d85db84..e07e682 100644 (file)
 /**
  * modest_text_utils_derived_subject:
  * @subject: a string which contains the original subject
- * @prefix: the prefix for the new subject (such as 'Re:' or 'Fwd:')
+ * @prefix: the prefix for the new subject (such as 'Re:' or 'Fwd:'),
+ *           must not be NULL
  *
  * create a 'derived' subject line for eg. replies and forwards 
  * 
  * Returns: a newly allocated string containing the resulting subject
+ * subject == NULL, then @prefix " " will be returned
  */
 gchar* modest_text_utils_derived_subject (const gchar *subject, 
                                          const gchar* prefix);
index 671076a..9baadb1 100644 (file)
@@ -43,6 +43,9 @@ START_TEST (test_display_address)
                { "Rupert Griffin (test)", "Rupert Griffin"},
                { "Hyvää päivää    ", "Hyvää päivää"},
        };
+
+       fail_unless (modest_text_utils_display_address (NULL) == NULL,
+                    "modest_text_utils_display_address(NULL) should be NULL");
        
        for (i = 0; i !=  sizeof(tests)/sizeof(StringPair); ++i) {
                gchar *str = g_strdup (tests[i].original);
@@ -56,6 +59,35 @@ START_TEST (test_display_address)
 }
 END_TEST
 
+START_TEST (test_derived_address)
+{
+       int i;
+       const gchar *prefix="Re:";
+       
+       const StringPair  tests[] = {
+               { "subject", "Re: subject" },
+               { NULL,      "Re:"},
+               { "Hyvää päivää", "Re: Hyvää päivää"},
+       };
+
+       fail_unless (modest_text_utils_derived_subject (NULL, NULL) == NULL,
+                    "modest_text_utils_derived_subject (NULL,NULL) should be NULL");
+       
+       for (i = 0; i !=  sizeof(tests)/sizeof(StringPair); ++i) {
+               gchar *str = g_strdup (tests[i].original);
+               str = modest_text_utils_derived_subject (str, prefix);
+               fail_unless (str && strcmp(str, tests[i].expected) == 0,
+                       "modest_text_utils_derived_subject failed for '%s': "
+                            "expected '%s' but got '%s'",
+                            tests[i].original, tests[i].expected, str);
+               g_free (str);
+       }
+}
+END_TEST
+
+
+
+
 
 
 static Suite*
@@ -63,9 +95,10 @@ text_utils_suite (void)
 {
        Suite *suite = suite_create ("ModestTextUtils");
 
-       TCase *tc_core = tcase_create ("core");
+       TCase *tc_core = tcase_create ("modest");
        tcase_add_test (tc_core, test_display_address);
-
+       tcase_add_test (tc_core, test_derived_address);
+       
        suite_add_tcase (suite, tc_core);
 
        return suite;