2011-05-22 09:27:12 +02:00
|
|
|
|
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
|
|
|
|
|
2011-10-23 23:20:05 +02:00
|
|
|
|
/*
|
2010-09-26 14:23:17 +02:00
|
|
|
|
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2010-01-28 21:21:57 +01:00
|
|
|
|
**
|
|
|
|
|
** This program is free software; you can redistribute it and/or modify it
|
|
|
|
|
** under the terms of the GNU General Public License as published by the
|
|
|
|
|
** Free Software Foundation; either version 3, or (at your option) any
|
|
|
|
|
** later version.
|
|
|
|
|
**
|
|
|
|
|
** This program is distributed in the hope that it will be useful,
|
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
|
**
|
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
|
** along with this program; if not, write to the Free Software Foundation,
|
2011-10-23 23:20:05 +02:00
|
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
**
|
2010-01-28 21:21:57 +01:00
|
|
|
|
*/
|
|
|
|
|
|
2010-11-02 20:14:24 +01:00
|
|
|
|
#if HAVE_CONFIG_H
|
2010-01-28 21:21:57 +01:00
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif /*HAVE_CONFIG_H*/
|
|
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
#include <locale.h>
|
2010-02-02 20:48:41 +01:00
|
|
|
|
|
|
|
|
|
#include "test-mu-common.h"
|
2012-05-20 16:41:18 +02:00
|
|
|
|
#include "mu-str.h"
|
|
|
|
|
#include "mu-msg-prio.h"
|
2010-01-28 21:21:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2010-11-22 23:44:18 +01:00
|
|
|
|
test_mu_str_size_01 (void)
|
2010-01-28 21:21:57 +01:00
|
|
|
|
{
|
2011-05-22 09:27:12 +02:00
|
|
|
|
struct lconv *lc;
|
|
|
|
|
char *tmp2;
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
lc = localeconv();
|
2010-01-28 21:21:57 +01:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
tmp2 = g_strdup_printf ("0%s0 kB", lc->decimal_point);
|
|
|
|
|
g_assert_cmpstr (mu_str_size_s (0), ==, tmp2);
|
|
|
|
|
g_free (tmp2);
|
2010-01-28 21:21:57 +01:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
tmp2 = g_strdup_printf ("100%s0 kB", lc->decimal_point);
|
|
|
|
|
g_assert_cmpstr (mu_str_size_s (100000), ==, tmp2);
|
|
|
|
|
g_free (tmp2);
|
2010-01-28 21:21:57 +01:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
tmp2 = g_strdup_printf ("1%s1 MB", lc->decimal_point);
|
|
|
|
|
g_assert_cmpstr (mu_str_size_s (1100*1000), ==, tmp2);
|
|
|
|
|
g_free (tmp2);
|
2010-01-28 21:21:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2010-01-28 21:21:57 +01:00
|
|
|
|
|
|
|
|
|
static void
|
2010-11-22 23:44:18 +01:00
|
|
|
|
test_mu_str_size_02 (void)
|
2010-01-28 21:21:57 +01:00
|
|
|
|
{
|
2011-05-22 09:27:12 +02:00
|
|
|
|
struct lconv *lc;
|
|
|
|
|
char *tmp1, *tmp2;
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
lc = localeconv();
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
tmp2 = g_strdup_printf ("1%s0 MB", lc->decimal_point);
|
2011-10-23 23:20:05 +02:00
|
|
|
|
tmp1 = mu_str_size (999999);
|
2011-05-22 09:27:12 +02:00
|
|
|
|
g_assert_cmpstr (tmp1, !=, tmp2);
|
2010-01-28 21:21:57 +01:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
g_free (tmp1);
|
|
|
|
|
g_free (tmp2);
|
2010-01-28 21:21:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2010-11-22 23:44:18 +01:00
|
|
|
|
test_mu_str_prio_01 (void)
|
2010-01-28 21:21:57 +01:00
|
|
|
|
{
|
2011-05-22 09:27:12 +02:00
|
|
|
|
g_assert_cmpstr(mu_msg_prio_name(MU_MSG_PRIO_LOW), ==, "low");
|
|
|
|
|
g_assert_cmpstr(mu_msg_prio_name(MU_MSG_PRIO_NORMAL), ==, "normal");
|
|
|
|
|
g_assert_cmpstr(mu_msg_prio_name(MU_MSG_PRIO_HIGH), ==, "high");
|
2010-01-28 21:21:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-21 12:43:40 +01:00
|
|
|
|
ignore_error (const char* log_domain, GLogLevelFlags log_level,
|
2011-05-22 09:27:12 +02:00
|
|
|
|
const gchar* msg, gpointer user_data)
|
2010-01-28 21:21:57 +01:00
|
|
|
|
{
|
2011-05-22 09:27:12 +02:00
|
|
|
|
return FALSE; /* don't abort */
|
2010-01-28 21:21:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2010-11-22 23:44:18 +01:00
|
|
|
|
test_mu_str_prio_02 (void)
|
2010-01-28 21:21:57 +01:00
|
|
|
|
{
|
2011-05-22 09:27:12 +02:00
|
|
|
|
/* this must fail */
|
|
|
|
|
g_test_log_set_fatal_handler ((GTestLogFatalFunc)ignore_error, NULL);
|
|
|
|
|
g_assert_cmpstr (mu_msg_prio_name(666), ==, NULL);
|
2010-01-28 21:21:57 +01:00
|
|
|
|
}
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2010-11-11 21:04:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2010-11-22 23:44:18 +01:00
|
|
|
|
test_mu_str_normalize_01 (void)
|
2010-11-11 21:04:47 +01:00
|
|
|
|
{
|
2011-05-22 09:27:12 +02:00
|
|
|
|
int i;
|
|
|
|
|
struct {
|
|
|
|
|
const char* word;
|
|
|
|
|
const char* norm;
|
|
|
|
|
} words [] = {
|
2011-10-23 23:20:05 +02:00
|
|
|
|
{ "dantès", "dantes"},
|
2011-05-22 09:27:12 +02:00
|
|
|
|
{ "foo", "foo" },
|
|
|
|
|
{ "Föö", "foo" },
|
|
|
|
|
{ "číslo", "cislo" },
|
|
|
|
|
{ "hÆvý mëÐal ümláõt", "haevy medal umlaot"}
|
|
|
|
|
};
|
2010-11-11 21:04:47 +01:00
|
|
|
|
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(words); ++i) {
|
|
|
|
|
gchar *str;
|
2012-06-11 23:11:52 +02:00
|
|
|
|
str = mu_str_normalize (words[i].word, TRUE, NULL);
|
2011-05-22 09:27:12 +02:00
|
|
|
|
g_assert_cmpstr (str, ==, words[i].norm);
|
|
|
|
|
g_free (str);
|
|
|
|
|
}
|
2010-11-11 21:04:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-11-29 20:21:55 +01:00
|
|
|
|
static void
|
|
|
|
|
test_mu_str_normalize_02 (void)
|
|
|
|
|
{
|
2011-05-22 09:27:12 +02:00
|
|
|
|
int i;
|
|
|
|
|
struct {
|
|
|
|
|
const char* word;
|
|
|
|
|
const char* norm;
|
|
|
|
|
} words [] = {
|
2011-10-23 23:20:05 +02:00
|
|
|
|
{ "DantèS", "DanteS"},
|
2011-05-22 09:27:12 +02:00
|
|
|
|
{ "foo", "foo" },
|
|
|
|
|
{ "Föö", "Foo" },
|
|
|
|
|
{ "číslO", "cislO" },
|
|
|
|
|
{ "hÆvý mëÐal ümláõt", "hAevy meDal umlaot"}
|
|
|
|
|
};
|
2010-11-29 20:21:55 +01:00
|
|
|
|
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(words); ++i) {
|
|
|
|
|
gchar *str;
|
2012-06-11 23:11:52 +02:00
|
|
|
|
str = mu_str_normalize (words[i].word, FALSE, NULL);
|
2011-05-22 09:27:12 +02:00
|
|
|
|
g_assert_cmpstr (str, ==, words[i].norm);
|
|
|
|
|
g_free (str);
|
|
|
|
|
}
|
2010-11-29 20:21:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-01-21 10:19:15 +01:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_mu_str_esc_to_list (void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
struct {
|
|
|
|
|
const char* str;
|
|
|
|
|
const char* strs[3];
|
|
|
|
|
} strings [] = {
|
|
|
|
|
{ "maildir:foo", {"maildir:foo", NULL, NULL}},
|
|
|
|
|
{ "maildir:sent items", {"maildir:sent", "items", NULL}},
|
|
|
|
|
{ "\"maildir:sent items\"", {"maildir:sent items", NULL, NULL}},
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(strings); ++i) {
|
|
|
|
|
GSList *lst, *cur;
|
|
|
|
|
unsigned u;
|
2012-03-30 17:45:06 +02:00
|
|
|
|
lst = mu_str_esc_to_list (strings[i].str, NULL);
|
2012-01-21 10:19:15 +01:00
|
|
|
|
for (cur = lst, u = 0; cur; cur = g_slist_next(cur), ++u)
|
|
|
|
|
g_assert_cmpstr ((const char*)cur->data,==,strings[i].strs[u]);
|
|
|
|
|
mu_str_free_list (lst);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 20:21:55 +01:00
|
|
|
|
static void
|
2012-04-16 00:10:46 +02:00
|
|
|
|
test_mu_str_xapian_escape (void)
|
2010-11-29 20:21:55 +01:00
|
|
|
|
{
|
2011-05-22 09:27:12 +02:00
|
|
|
|
int i;
|
|
|
|
|
struct {
|
|
|
|
|
const char* word;
|
|
|
|
|
const char* esc;
|
|
|
|
|
} words [] = {
|
2011-10-23 23:20:05 +02:00
|
|
|
|
{ "aap@noot.mies", "aap_noot_mies"},
|
2012-04-13 21:05:17 +02:00
|
|
|
|
{ "Foo..Bar", "foo__bar" },
|
2011-05-22 09:27:12 +02:00
|
|
|
|
{ "Foo.Bar", "foo_bar" },
|
2012-01-21 10:19:15 +01:00
|
|
|
|
{ "Foo. Bar", "foo__bar" },
|
2011-05-22 09:27:12 +02:00
|
|
|
|
{ "subject:test@foo", "subject:test_foo" },
|
2012-01-21 10:19:15 +01:00
|
|
|
|
{ "xxx:test@bar", "xxx_test_bar" },
|
2012-04-13 21:05:17 +02:00
|
|
|
|
{ "aa$bb$cc", "aa_bb_cc" },
|
|
|
|
|
{ "date:2010..2012", "date:2010..2012"},
|
|
|
|
|
{ "d:2010..2012", "d:2010..2012"},
|
|
|
|
|
{ "size:10..20", "size:10..20"},
|
|
|
|
|
{ "x:2010..2012", "x:2010__2012"},
|
|
|
|
|
{ "q:2010..2012", "q_2010__2012"},
|
2012-05-04 19:58:34 +02:00
|
|
|
|
{ "subject:2010..2012", "subject:2010__2012"},
|
|
|
|
|
{ "(maildir:foo)", "(maildir:foo)"}
|
2011-05-22 09:27:12 +02:00
|
|
|
|
};
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(words); ++i) {
|
|
|
|
|
gchar *a = g_strdup (words[i].word);
|
2012-06-11 23:11:52 +02:00
|
|
|
|
mu_str_xapian_escape_in_place_try (a, FALSE, NULL);
|
2012-04-13 21:05:17 +02:00
|
|
|
|
|
|
|
|
|
if (g_test_verbose())
|
|
|
|
|
g_print ("expected: '%s' <=> got: '%s'\n",
|
|
|
|
|
words[i].esc, a);
|
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
g_assert_cmpstr (a, ==, words[i].esc);
|
|
|
|
|
g_free (a);
|
|
|
|
|
}
|
2010-11-29 20:21:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-04-16 00:10:46 +02:00
|
|
|
|
static void
|
|
|
|
|
test_mu_str_xapian_escape_non_ascii (void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
struct {
|
|
|
|
|
const char* word;
|
|
|
|
|
const char* esc;
|
|
|
|
|
} words [] = {
|
|
|
|
|
{ "Тесла, Никола", "тесла__никола"},
|
|
|
|
|
{ "Masha@Аркона.ru", "masha_аркона_ru" },
|
|
|
|
|
{ "foo:ελληνικά", "foo_ελληνικά" },
|
|
|
|
|
{ "日本語!!", "日本語__" },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(words); ++i) {
|
|
|
|
|
gchar *a = g_strdup (words[i].word);
|
2012-06-11 23:11:52 +02:00
|
|
|
|
mu_str_xapian_escape_in_place_try (a, FALSE, NULL);
|
2012-04-16 00:10:46 +02:00
|
|
|
|
|
|
|
|
|
if (g_test_verbose())
|
|
|
|
|
g_print ("(%s) expected: '%s' <=> got: '%s'\n",
|
|
|
|
|
words[i].word, words[i].esc, a);
|
|
|
|
|
|
|
|
|
|
g_assert_cmpstr (a, ==, words[i].esc);
|
|
|
|
|
g_free (a);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-23 21:05:55 +01:00
|
|
|
|
static void
|
2010-11-30 21:33:15 +01:00
|
|
|
|
test_mu_str_display_contact (void)
|
2010-11-23 21:05:55 +01:00
|
|
|
|
{
|
2011-05-22 09:27:12 +02:00
|
|
|
|
int i;
|
|
|
|
|
struct {
|
|
|
|
|
const char* word;
|
|
|
|
|
const char* disp;
|
|
|
|
|
} words [] = {
|
2011-10-23 23:20:05 +02:00
|
|
|
|
{ "\"Foo Bar\" <aap@noot.mies>", "Foo Bar"},
|
2011-05-22 09:27:12 +02:00
|
|
|
|
{ "Foo Bar <aap@noot.mies>", "Foo Bar" },
|
|
|
|
|
{ "<aap@noot.mies>", "aap@noot.mies" },
|
|
|
|
|
{ "foo@bar.nl", "foo@bar.nl" }
|
|
|
|
|
};
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(words); ++i)
|
|
|
|
|
g_assert_cmpstr (mu_str_display_contact_s (words[i].word), ==,
|
2011-05-22 09:27:12 +02:00
|
|
|
|
words[i].disp);
|
2010-11-23 21:05:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-06-15 22:44:52 +02:00
|
|
|
|
static void
|
|
|
|
|
assert_cmplst (GSList *lst, const char *items[])
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2011-10-23 23:20:05 +02:00
|
|
|
|
if (!lst)
|
2011-06-15 22:44:52 +02:00
|
|
|
|
g_assert (!items);
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
|
|
|
|
for (i = 0; lst; lst = g_slist_next(lst), ++i)
|
2011-06-15 22:44:52 +02:00
|
|
|
|
g_assert_cmpstr ((char*)lst->data,==,items[i]);
|
|
|
|
|
|
|
|
|
|
g_assert (items[i] == NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static GSList*
|
|
|
|
|
create_list (const char *items[])
|
|
|
|
|
{
|
|
|
|
|
GSList *lst;
|
|
|
|
|
|
|
|
|
|
lst = NULL;
|
|
|
|
|
while (items && *items) {
|
|
|
|
|
lst = g_slist_prepend (lst, g_strdup(*items));
|
|
|
|
|
++items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return g_slist_reverse (lst);
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-06-15 22:44:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_mu_str_from_list (void)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
const char *strs[] = {"aap", "noot", "mies", NULL};
|
|
|
|
|
GSList *lst = create_list (strs);
|
|
|
|
|
gchar *str = mu_str_from_list (lst, ',');
|
|
|
|
|
g_assert_cmpstr ("aap,noot,mies", ==, str);
|
|
|
|
|
mu_str_free_list (lst);
|
|
|
|
|
g_free (str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const char *strs[] = {"aap", "no,ot", "mies", NULL};
|
|
|
|
|
GSList *lst = create_list (strs);
|
|
|
|
|
gchar *str = mu_str_from_list (lst, ',');
|
|
|
|
|
g_assert_cmpstr ("aap,no,ot,mies", ==, str);
|
|
|
|
|
mu_str_free_list (lst);
|
|
|
|
|
g_free (str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const char *strs[] = {NULL};
|
|
|
|
|
GSList *lst = create_list (strs);
|
|
|
|
|
gchar *str = mu_str_from_list (lst,'@');
|
|
|
|
|
g_assert_cmpstr (NULL, ==, str);
|
|
|
|
|
mu_str_free_list (lst);
|
|
|
|
|
g_free (str);
|
|
|
|
|
}
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-06-15 22:44:52 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_mu_str_to_list (void)
|
|
|
|
|
{
|
|
|
|
|
{
|
2011-07-06 01:14:00 +02:00
|
|
|
|
const char *items[]= {"foo", "bar ", "cuux", NULL};
|
|
|
|
|
GSList *lst = mu_str_to_list ("foo@bar @cuux",'@', FALSE);
|
2011-06-15 22:44:52 +02:00
|
|
|
|
assert_cmplst (lst, items);
|
|
|
|
|
mu_str_free_list (lst);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2011-07-06 01:14:00 +02:00
|
|
|
|
GSList *lst = mu_str_to_list (NULL,'x',FALSE);
|
2011-06-15 22:44:52 +02:00
|
|
|
|
g_assert (lst == NULL);
|
|
|
|
|
mu_str_free_list (lst);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-06 01:14:00 +02:00
|
|
|
|
static void
|
|
|
|
|
test_mu_str_to_list_strip (void)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
const char *items[]= {"foo", "bar", "cuux", NULL};
|
|
|
|
|
GSList *lst = mu_str_to_list ("foo@bar @cuux",'@', TRUE);
|
|
|
|
|
assert_cmplst (lst, items);
|
|
|
|
|
mu_str_free_list (lst);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-06-15 22:44:52 +02:00
|
|
|
|
|
|
|
|
|
|
2011-03-06 11:14:26 +01:00
|
|
|
|
static void
|
|
|
|
|
test_mu_str_guess_first_name (void)
|
|
|
|
|
{
|
2011-05-22 09:27:12 +02:00
|
|
|
|
int i;
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
struct {
|
|
|
|
|
char *src, *exp;
|
|
|
|
|
} tests[] = {
|
|
|
|
|
{ "Richard M. Stallman", "Richard M." },
|
|
|
|
|
{ "John Rambo", "John" },
|
|
|
|
|
{ "Ivanhoe", "Ivanhoe" },
|
|
|
|
|
{ "", "" }
|
|
|
|
|
};
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(tests); ++i) {
|
|
|
|
|
gchar *s;
|
2011-03-06 11:14:26 +01:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
s = mu_str_guess_first_name (tests[i].src);
|
|
|
|
|
g_assert_cmpstr (s, ==, tests[i].exp);
|
|
|
|
|
g_free (s);
|
|
|
|
|
}
|
2011-03-06 11:14:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_mu_str_guess_last_name (void)
|
|
|
|
|
{
|
2011-05-22 09:27:12 +02:00
|
|
|
|
int i;
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
struct {
|
|
|
|
|
char *src, *exp;
|
|
|
|
|
} tests[] = {
|
|
|
|
|
{ "Richard M. Stallman", "Stallman" },
|
|
|
|
|
{ "John Rambo", "Rambo" },
|
|
|
|
|
{ "Ivanhoe", "" },
|
|
|
|
|
{ "", "" }
|
|
|
|
|
};
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(tests); ++i) {
|
|
|
|
|
gchar *s;
|
2011-03-06 11:14:26 +01:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
s = mu_str_guess_last_name (tests[i].src);
|
|
|
|
|
g_assert_cmpstr (s, ==, tests[i].exp);
|
|
|
|
|
g_free (s);
|
|
|
|
|
}
|
2011-03-06 11:14:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_mu_str_guess_nick (void)
|
|
|
|
|
{
|
2011-05-22 09:27:12 +02:00
|
|
|
|
int i;
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
struct {
|
|
|
|
|
char *src, *exp;
|
|
|
|
|
} tests[] = {
|
|
|
|
|
{ "Richard M. Stallman", "RichardMS" },
|
|
|
|
|
{ "John Rambo", "JohnR" },
|
|
|
|
|
{ "Ivanhoe", "Ivanhoe" },
|
|
|
|
|
{ "", "" }
|
|
|
|
|
};
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(tests); ++i) {
|
|
|
|
|
gchar *s;
|
2011-03-06 11:14:26 +01:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
s = mu_str_guess_nick (tests[i].src);
|
|
|
|
|
g_assert_cmpstr (s, ==, tests[i].exp);
|
|
|
|
|
g_free (s);
|
|
|
|
|
}
|
2011-03-06 11:14:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-07-02 11:48:46 +02:00
|
|
|
|
static void
|
|
|
|
|
test_mu_str_subject_normalize (void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-07-02 11:48:46 +02:00
|
|
|
|
struct {
|
|
|
|
|
char *src, *exp;
|
|
|
|
|
} tests[] = {
|
|
|
|
|
{ "test123", "test123" },
|
|
|
|
|
{ "Re:test123", "test123" },
|
|
|
|
|
{ "Re: Fwd: test123", "test123" },
|
|
|
|
|
{ "Re[3]: Fwd: test123", "test123" },
|
2012-06-15 17:21:21 +02:00
|
|
|
|
{ "operation: mindcrime", "operation: mindcrime" }, /*...*/
|
2011-07-02 11:48:46 +02:00
|
|
|
|
{ "", "" }
|
|
|
|
|
};
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-07-02 11:48:46 +02:00
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(tests); ++i)
|
|
|
|
|
g_assert_cmpstr (mu_str_subject_normalize (tests[i].src), ==,
|
|
|
|
|
tests[i].exp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-03-06 11:14:26 +01:00
|
|
|
|
|
|
|
|
|
|
2010-01-28 21:21:57 +01:00
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
|
{
|
2011-05-22 09:27:12 +02:00
|
|
|
|
g_test_init (&argc, &argv, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* mu_str_size */
|
|
|
|
|
g_test_add_func ("/mu-str/mu-str-size-01",
|
|
|
|
|
test_mu_str_size_01);
|
|
|
|
|
g_test_add_func ("/mu-str/mu-str-size-02",
|
|
|
|
|
test_mu_str_size_02);
|
|
|
|
|
|
|
|
|
|
/* mu_str_prio */
|
|
|
|
|
g_test_add_func ("/mu-str/mu-str-prio-01",
|
|
|
|
|
test_mu_str_prio_01);
|
|
|
|
|
g_test_add_func ("/mu-str/mu-str-prio-02",
|
|
|
|
|
test_mu_str_prio_02);
|
|
|
|
|
|
|
|
|
|
/* mu_str_normalize */
|
|
|
|
|
g_test_add_func ("/mu-str/mu-str-normalize-01",
|
|
|
|
|
test_mu_str_normalize_01);
|
|
|
|
|
g_test_add_func ("/mu-str/mu-str-normalize-02",
|
|
|
|
|
test_mu_str_normalize_02);
|
|
|
|
|
|
2012-04-16 00:10:46 +02:00
|
|
|
|
g_test_add_func ("/mu-str/mu-str-xapian-escape",
|
|
|
|
|
test_mu_str_xapian_escape);
|
|
|
|
|
g_test_add_func ("/mu-str/mu-str-xapian-escape-non-ascii",
|
|
|
|
|
test_mu_str_xapian_escape_non_ascii);
|
2011-05-22 09:27:12 +02:00
|
|
|
|
|
|
|
|
|
g_test_add_func ("/mu-str/mu-str-display_contact",
|
2011-10-23 23:20:05 +02:00
|
|
|
|
test_mu_str_display_contact);
|
|
|
|
|
|
2011-06-15 22:44:52 +02:00
|
|
|
|
g_test_add_func ("/mu-str/mu-str-from-list",
|
|
|
|
|
test_mu_str_from_list);
|
|
|
|
|
g_test_add_func ("/mu-str/mu-str-to-list",
|
|
|
|
|
test_mu_str_to_list);
|
2011-07-06 01:14:00 +02:00
|
|
|
|
g_test_add_func ("/mu-str/mu-str-to-list-strip",
|
|
|
|
|
test_mu_str_to_list_strip);
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2012-01-21 10:19:15 +01:00
|
|
|
|
g_test_add_func ("/mu-str/mu-str-esc-to-list",
|
|
|
|
|
test_mu_str_esc_to_list);
|
|
|
|
|
|
2011-07-02 11:48:46 +02:00
|
|
|
|
g_test_add_func ("/mu-str/mu_str_guess_first_name",
|
2011-05-22 09:27:12 +02:00
|
|
|
|
test_mu_str_guess_first_name);
|
2011-07-02 11:48:46 +02:00
|
|
|
|
g_test_add_func ("/mu-str/mu_str_guess_last_name",
|
2011-05-22 09:27:12 +02:00
|
|
|
|
test_mu_str_guess_last_name);
|
2011-07-02 11:48:46 +02:00
|
|
|
|
g_test_add_func ("/mu-str/mu_str_guess_nick",
|
2011-05-22 09:27:12 +02:00
|
|
|
|
test_mu_str_guess_nick);
|
2011-07-02 11:48:46 +02:00
|
|
|
|
|
|
|
|
|
g_test_add_func ("/mu-str/mu_str_subject_normalize",
|
|
|
|
|
test_mu_str_subject_normalize);
|
|
|
|
|
|
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
/* FIXME: add tests for mu_str_flags; but note the
|
|
|
|
|
* function simply calls mu_msg_field_str */
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
g_log_set_handler (NULL,
|
|
|
|
|
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
|
|
|
|
(GLogFunc)black_hole, NULL);
|
2011-10-23 23:20:05 +02:00
|
|
|
|
|
2011-05-22 09:27:12 +02:00
|
|
|
|
return g_test_run ();
|
2010-01-28 21:21:57 +01:00
|
|
|
|
}
|