From 92e543c8035106d692674a13de97e99b66ba6927 Mon Sep 17 00:00:00 2001 From: djcb Date: Mon, 24 Oct 2011 00:20:05 +0300 Subject: [PATCH] * fix unit tests (i.e.. fix re-indexing messages bug) --- src/mu-msg-file.c | 165 +++++++++++++++++++------------------- src/mu-store-read.cc | 16 ++-- src/mu-store-write.cc | 33 ++++---- src/mu-str.c | 2 +- src/tests/test-mu-query.c | 3 +- src/tests/test-mu-str.c | 76 +++++++++--------- 6 files changed, 151 insertions(+), 144 deletions(-) diff --git a/src/mu-msg-file.c b/src/mu-msg-file.c index 2976c6ad..b84ec9f5 100644 --- a/src/mu-msg-file.c +++ b/src/mu-msg-file.c @@ -37,7 +37,6 @@ #endif /*PATH_MAX */ #include - #include "mu-util.h" #include "mu-str.h" #include "mu-maildir.h" @@ -49,25 +48,25 @@ static gboolean init_file_metadata (MuMsgFile *self, const char* path, static gboolean init_mime_msg (MuMsgFile *msg, const char *path, GError **err); -MuMsgFile* +MuMsgFile* mu_msg_file_new (const char* filepath, const char *mdir, GError **err) { MuMsgFile *self; g_return_val_if_fail (filepath, NULL); - - self = g_slice_new0 (MuMsgFile); - + + self = g_slice_new0 (MuMsgFile); + if (!init_file_metadata (self, filepath, mdir, err)) { mu_msg_file_destroy (self); return NULL; } - + if (!init_mime_msg (self, filepath, err)) { mu_msg_file_destroy (self); return NULL; } - + return self; } @@ -80,7 +79,7 @@ mu_msg_file_destroy (MuMsgFile *self) if (self->_mime_msg) g_object_unref (self->_mime_msg); - + g_slice_free (MuMsgFile, self); } @@ -104,19 +103,19 @@ init_file_metadata (MuMsgFile *self, const char* path, const gchar* mdir, path, strerror(errno)); return FALSE; } - + if (!S_ISREG(statbuf.st_mode)) { g_set_error (err, 0, MU_ERROR_FILE, "not a regular file: %s", path); return FALSE; } - + self->_timestamp = statbuf.st_mtime; self->_size = (size_t)statbuf.st_size; strncpy (self->_path, path, PATH_MAX); - strncpy (self->_maildir, mdir ? mdir : "", PATH_MAX); - + strncpy (self->_maildir, mdir ? mdir : "", PATH_MAX); + return TRUE; } @@ -127,7 +126,7 @@ get_mime_stream (MuMsgFile *self, const char *path, GError **err) { FILE *file; GMimeStream *stream; - + file = fopen (path, "r"); if (!file) { g_set_error (err, 0, MU_ERROR_FILE, @@ -135,7 +134,7 @@ get_mime_stream (MuMsgFile *self, const char *path, GError **err) path, strerror (errno)); return NULL; } - + stream = g_mime_stream_file_new (file); if (!stream) { g_set_error (err, 0, MU_ERROR_GMIME, @@ -153,11 +152,11 @@ init_mime_msg (MuMsgFile *self, const char* path, GError **err) { GMimeStream *stream; GMimeParser *parser; - + stream = get_mime_stream (self, path, err); if (!stream) return FALSE; - + parser = g_mime_parser_new_with_stream (stream); g_object_unref (stream); if (!parser) { @@ -166,7 +165,7 @@ init_mime_msg (MuMsgFile *self, const char* path, GError **err) __FUNCTION__, path); return FALSE; } - + self->_mime_msg = g_mime_parser_construct_message (parser); g_object_unref (parser); if (!self->_mime_msg) { @@ -185,7 +184,7 @@ get_recipient (MuMsgFile *self, GMimeRecipientType rtype) { char *recip; InternetAddressList *recips; - + recips = g_mime_message_get_recipients (self->_mime_msg, rtype); /* FALSE --> don't encode */ @@ -195,7 +194,7 @@ get_recipient (MuMsgFile *self, GMimeRecipientType rtype) g_debug ("invalid recipient in %s\n", self->_path); mu_str_asciify_in_place (recip); /* ugly... */ } - + if (mu_str_is_empty(recip)) { g_free (recip); return NULL; @@ -211,12 +210,12 @@ part_looks_like_attachment (GMimeObject *part) { GMimeContentDisposition *disp; const char *str; - + disp = g_mime_object_get_content_disposition (part); if (!GMIME_IS_CONTENT_DISPOSITION(disp)) return FALSE; /* no content disp? prob not * an attachment. */ - + str = g_mime_content_disposition_get_disposition (disp); /* ok, it says it's an attachment, so it probably is... */ @@ -232,20 +231,20 @@ part_looks_like_attachment (GMimeObject *part) return g_mime_content_type_is_type (ct, "image", "*"); } - + return FALSE; } - + static void msg_cflags_cb (GMimeObject *parent, GMimeObject *part, MuFlags *flags) { if (*flags & MU_FLAG_HAS_ATTACH) return; - + if (!GMIME_IS_PART(part)) return; - + if (part_looks_like_attachment(part)) *flags |= MU_FLAG_HAS_ATTACH; } @@ -264,9 +263,9 @@ get_content_flags (MuMsgFile *self) flags = 0; g_mime_message_foreach (self->_mime_msg, - (GMimeObjectForeachFunc)msg_cflags_cb, + (GMimeObjectForeachFunc)msg_cflags_cb, &flags); - + /* note: signed or encrypted status for a message is determined by * the top-level mime-part */ @@ -276,14 +275,14 @@ get_content_flags (MuMsgFile *self) if (!ctype) { g_warning ("not a content type!"); return 0; - } - + } + if (ctype) { if (g_mime_content_type_is_type - (ctype,"*", "signed")) + (ctype,"*", "signed")) flags |= MU_FLAG_SIGNED; if (g_mime_content_type_is_type - (ctype,"*", "encrypted")) + (ctype,"*", "encrypted")) flags |= MU_FLAG_ENCRYPTED; } } else @@ -297,7 +296,7 @@ static MuFlags get_flags (MuMsgFile *self) { MuFlags flags; - + g_return_val_if_fail (self, MU_FLAG_INVALID); flags = mu_maildir_get_flags_from_path (self->_path); @@ -307,7 +306,7 @@ get_flags (MuMsgFile *self) * for searching convenience */ if ((flags & MU_FLAG_NEW) || !(flags & MU_FLAG_SEEN)) flags |= MU_FLAG_UNREAD; - + return flags; } @@ -348,7 +347,7 @@ get_prio_header_field (MuMsgFile *self) str = g_mime_object_get_header (obj, "Importance"); if (!str) str = g_mime_object_get_header (obj, "Precedence"); - if (str) + if (str) return (to_lower(g_strdup(str))); else return NULL; @@ -366,7 +365,7 @@ parse_prio_str (const char* priostr) { "high", MU_MSG_PRIO_HIGH }, { "1", MU_MSG_PRIO_HIGH }, { "2", MU_MSG_PRIO_HIGH }, - + { "normal", MU_MSG_PRIO_NORMAL }, { "3", MU_MSG_PRIO_NORMAL }, @@ -380,7 +379,7 @@ parse_prio_str (const char* priostr) for (i = 0; i != G_N_ELEMENTS(str_prio); ++i) if (g_strstr_len (priostr, -1, str_prio[i]._str) != NULL) return str_prio[i]._prio; - + /* e.g., last-fm uses 'fm-user'... as precedence */ return MU_MSG_PRIO_NORMAL; } @@ -396,7 +395,7 @@ get_prio (MuMsgFile *self) priostr = get_prio_header_field (self); if (!priostr) return MU_MSG_PRIO_NORMAL; - + prio = parse_prio_str (priostr); g_free (priostr); @@ -416,40 +415,40 @@ looks_like_attachment (GMimeObject *part) { const char *str; GMimeContentDisposition *disp; - + disp = g_mime_object_get_content_disposition (GMIME_OBJECT(part)); if (!GMIME_IS_CONTENT_DISPOSITION(disp)) - return FALSE; + return FALSE; str = g_mime_content_disposition_get_disposition (disp); if (!str) return FALSE; - + if (strcmp(str,GMIME_DISPOSITION_INLINE) == 0) return FALSE; /* inline, so it's not an attachment */ - + return TRUE; /* looks like an attachment */ } static void get_body_cb (GMimeObject *parent, GMimeObject *part, GetBodyData *data) { - GMimeContentType *ct; + GMimeContentType *ct; /* already found what we're looking for? */ if ((data->_want_html && data->_html_part != NULL) || (!data->_want_html && data->_txt_part != NULL)) return; - + ct = g_mime_object_get_content_type (part); if (!GMIME_IS_CONTENT_TYPE(ct)) { g_warning ("not a content type!"); return; } - + if (looks_like_attachment (part)) return; /* not the body */ - + /* is it right content type? */ if (g_mime_content_type_is_type (ct, "text", "plain")) data->_txt_part = part; @@ -457,7 +456,7 @@ get_body_cb (GMimeObject *parent, GMimeObject *part, GetBodyData *data) data->_html_part = part; else return; /* wrong type */ -} +} @@ -468,20 +467,20 @@ convert_to_utf8 (GMimePart *part, char *buffer) GMimeContentType *ctype; const char* charset; unsigned char *cur; - + /* optimization: if the buffer is plain ascii, no conversion * is done... */ for (cur = (unsigned char*)buffer; *cur && *cur < 0x80; ++cur); if (*cur == '\0') return buffer; - + ctype = g_mime_object_get_content_type (GMIME_OBJECT(part)); g_return_val_if_fail (GMIME_IS_CONTENT_TYPE(ctype), NULL); - + charset = g_mime_content_type_get_parameter (ctype, "charset"); - if (charset) + if (charset) charset = g_mime_charset_iconv_name (charset); - + /* of course, the charset specified may be incorrect... */ if (charset) { char *utf8 = mu_str_convert_to_utf8 (buffer, charset); @@ -503,10 +502,10 @@ stream_to_string (GMimeStream *stream, size_t buflen) { char *buffer; ssize_t bytes; - + buffer = g_new(char, buflen + 1); g_mime_stream_reset (stream); - + /* we read everything in one go */ bytes = g_mime_stream_read (stream, buffer, buflen); if (bytes < 0) { @@ -514,8 +513,8 @@ stream_to_string (GMimeStream *stream, size_t buflen) g_free (buffer); return NULL; } - - buffer[bytes]='\0'; + + buffer[bytes]='\0'; return buffer; } @@ -531,7 +530,7 @@ part_to_string (GMimePart *part, gboolean *err) *err = TRUE; g_return_val_if_fail (GMIME_IS_PART(part), NULL); - + wrapper = g_mime_part_get_content_object (part); if (!wrapper) { /* this happens with invalid mails */ @@ -550,18 +549,18 @@ part_to_string (GMimePart *part, gboolean *err) *err = FALSE; goto cleanup; } - + buffer = stream_to_string (stream, (size_t)buflen); - + /* convert_to_utf8 will free the old 'buffer' if needed */ buffer = convert_to_utf8 (part, buffer); - + *err = FALSE; - -cleanup: + +cleanup: if (stream) g_object_unref (G_OBJECT(stream)); - + return buffer; } @@ -572,10 +571,10 @@ get_body (MuMsgFile *self, gboolean want_html) GetBodyData data; char *str; gboolean err; - + g_return_val_if_fail (self, NULL); g_return_val_if_fail (GMIME_IS_MESSAGE(self->_mime_msg), NULL); - + memset (&data, 0, sizeof(GetBodyData)); data._want_html = want_html; @@ -586,7 +585,7 @@ get_body (MuMsgFile *self, gboolean want_html) if (want_html) str = data._html_part ? part_to_string (GMIME_PART(data._html_part), &err) : - NULL; + NULL; else str = data._txt_part ? part_to_string (GMIME_PART(data._txt_part), &err) : @@ -594,8 +593,8 @@ get_body (MuMsgFile *self, gboolean want_html) /* note, str may be NULL (no body), but that's not necessarily * an error; we only warn when an actual error occured */ - if (err) - g_warning ("error occured while retrieving %s body" + if (err) + g_warning ("error occured while retrieving %s body" "for message %s", want_html ? "html" : "text", self->_path); return str; @@ -620,17 +619,17 @@ get_references (MuMsgFile *self) const char *str; unsigned u; const char *headers[] = { "References", "In-reply-to", NULL }; - + for (msgids = NULL, u = 0; headers[u]; ++u) { const GMimeReferences *cur; GMimeReferences *mime_refs; - + str = g_mime_object_get_header (GMIME_OBJECT(self->_mime_msg), headers[u]); if (!str) continue; - + mime_refs = g_mime_references_decode (str); for (cur = mime_refs; cur; cur = g_mime_references_get_next(cur)) { const char* msgid; @@ -642,7 +641,7 @@ get_references (MuMsgFile *self) g_mime_references_free (mime_refs); } - + return g_slist_reverse (msgids); } @@ -651,11 +650,11 @@ static GSList* get_tags (MuMsgFile *self) { GMimeObject *obj; - + obj = GMIME_OBJECT(self->_mime_msg); return mu_str_to_list (g_mime_object_get_header - (obj, "X-Label"), ',', TRUE); + (obj, "X-Label"), ',', TRUE); } @@ -669,7 +668,7 @@ maybe_cleanup (const char* str, const char *path, gboolean *do_free) return (char*)str; g_debug ("invalid utf8 in %s", path); - + if (*do_free) return mu_str_asciify_in_place ((char*)str); else { @@ -689,7 +688,7 @@ mu_msg_file_get_str_field (MuMsgFile *self, MuMsgFieldId mfid, g_return_val_if_fail (mu_msg_field_is_string(mfid), NULL); *do_free = FALSE; /* default */ - + switch (mfid) { case MU_MSG_FIELD_ID_BCC: *do_free = TRUE; @@ -710,7 +709,7 @@ mu_msg_file_get_str_field (MuMsgFile *self, MuMsgFieldId mfid, self->_path, do_free); case MU_MSG_FIELD_ID_PATH: return self->_path; - + case MU_MSG_FIELD_ID_SUBJECT: return (char*)maybe_cleanup (g_mime_message_get_subject (self->_mime_msg), @@ -723,7 +722,7 @@ mu_msg_file_get_str_field (MuMsgFile *self, MuMsgFieldId mfid, return (char*)g_mime_message_get_message_id (self->_mime_msg); case MU_MSG_FIELD_ID_MAILDIR: return self->_maildir; - + default: g_return_val_if_reached (NULL); } } @@ -735,9 +734,9 @@ mu_msg_file_get_str_list_field (MuMsgFile *self, MuMsgFieldId mfid, { g_return_val_if_fail (self, NULL); g_return_val_if_fail (mu_msg_field_is_string_list(mfid), NULL); - + switch (mfid) { - + case MU_MSG_FIELD_ID_REFS: *do_free = TRUE; return get_references (self); @@ -755,15 +754,15 @@ mu_msg_file_get_num_field (MuMsgFile *self, const MuMsgFieldId mfid) { g_return_val_if_fail (self, -1); g_return_val_if_fail (mu_msg_field_is_numeric(mfid), -1); - + switch (mfid) { - + case MU_MSG_FIELD_ID_DATE: { time_t t; g_mime_message_get_date (self->_mime_msg, &t, NULL); return (time_t)t; } - + case MU_MSG_FIELD_ID_FLAGS: return (gint64)get_flags(self); @@ -784,7 +783,7 @@ mu_msg_file_get_header (MuMsgFile *self, const char *header) { g_return_val_if_fail (self, NULL); g_return_val_if_fail (header, NULL); - + return g_mime_object_get_header (GMIME_OBJECT(self->_mime_msg), header); } diff --git a/src/mu-store-read.cc b/src/mu-store-read.cc index 217db865..57de42a6 100644 --- a/src/mu-store-read.cc +++ b/src/mu-store-read.cc @@ -49,20 +49,19 @@ _MuStore::get_uid_term (const char* path) unsigned djbhash, bkdrhash, bkdrseed; unsigned u; - static char hex[10]; + static char hex[18]; djbhash = 5381; bkdrhash = 0; bkdrseed = 1313; - for(u = 0; path[u]; ++u) { djbhash = ((djbhash << 5) + djbhash) + path[u]; bkdrhash = bkdrhash * bkdrseed + path[u]; } snprintf (hex, sizeof(hex), - MU_STORE_UID_PREFIX "%04x%04x", + MU_STORE_UID_PREFIX "%08x%08x", djbhash, bkdrhash); return hex; @@ -162,8 +161,12 @@ mu_store_contains_message (MuStore *store, const char* path, GError **err) g_return_val_if_fail (path, FALSE); try { - const std::string uid (store->get_uid_term (path)); - return store->db_read_only()->term_exists (uid) ? TRUE: FALSE; + const std::string term (store->get_uid_term(path)); + + MU_WRITE_LOG ("term exists? '%s': %s", term.c_str(), + store->db_read_only()->term_exists (term) ? "yes" : "no"); + + return store->db_read_only()->term_exists (term) ? TRUE: FALSE; } MU_XAPIAN_CATCH_BLOCK_G_ERROR_RETURN(err, MU_ERROR_XAPIAN, FALSE); @@ -177,7 +180,8 @@ mu_store_get_docid_for_path (MuStore *store, const char* path, GError **err) g_return_val_if_fail (path, FALSE); try { - Xapian::Query query (store->get_uid_term (path)); // uid is a term + const std::string term (store->get_uid_term(path)); + Xapian::Query query (term); Xapian::Enquire enq (*store->db_read_only()); enq.set_query (query); diff --git a/src/mu-store-write.cc b/src/mu-store-write.cc index e01d5c59..988aa0c2 100644 --- a/src/mu-store-write.cc +++ b/src/mu-store-write.cc @@ -88,7 +88,7 @@ prefix (MuMsgFieldId mfid) static void add_synonym_for_flag (MuFlags flag, Xapian::WritableDatabase *db) { - const std::string pfx(prefix(MU_MSG_FIELD_ID_FLAGS)); + static const std::string pfx(prefix(MU_MSG_FIELD_ID_FLAGS)); db->clear_synonyms (pfx + mu_flag_name (flag)); db->add_synonym (pfx + mu_flag_name (flag), pfx + @@ -99,7 +99,7 @@ add_synonym_for_flag (MuFlags flag, Xapian::WritableDatabase *db) static void add_synonym_for_prio (MuMsgPrio prio, Xapian::WritableDatabase *db) { - const std::string pfx (prefix(MU_MSG_FIELD_ID_PRIO)); + static const std::string pfx (prefix(MU_MSG_FIELD_ID_PRIO)); std::string s1 (pfx + mu_msg_prio_name (prio)); std::string s2 (pfx + (std::string(1, mu_msg_prio_char (prio)))); @@ -567,6 +567,7 @@ new_doc_from_message (MuStore *store, MuMsg *msg) /* also store the contact-info as separate terms */ mu_msg_contact_foreach (msg, (MuMsgContactForeachFunc)each_contact_info, &docinfo); + return doc; } @@ -580,17 +581,18 @@ mu_store_add_msg (MuStore *store, MuMsg *msg, GError **err) try { Xapian::docid id; Xapian::Document doc (new_doc_from_message(store, msg)); - const std::string uid (store->get_uid_term(mu_msg_get_path(msg))); + const std::string term (store->get_uid_term + (mu_msg_get_path(msg))); if (!store->in_transaction()) store->begin_transaction(); - /* note, this will replace any other messages for this path */ - doc.add_term (uid); - id = store->db_writable()->replace_document (uid, doc); + doc.add_term (term); - MU_WRITE_LOG ("add %s (%s)", - mu_msg_get_path (msg), uid.c_str()); + MU_WRITE_LOG ("adding: %s", term.c_str()); + + /* note, this will replace any other messages for this path */ + id = store->db_writable()->replace_document (term, doc); if (store->inc_processed() % store->batch_size() == 0) store->commit_transaction(); @@ -619,12 +621,12 @@ mu_store_update_msg (MuStore *store, unsigned docid, MuMsg *msg, GError **err) if (!store->in_transaction()) store->begin_transaction(); - store->db_writable()->replace_document (docid, doc); - MU_WRITE_LOG ("update %s (%s) %u", - mu_msg_get_path (msg), - store->get_uid_term(mu_msg_get_path(msg)), - docid); + const std::string term + (store->get_uid_term(mu_msg_get_path(msg))); + doc.add_term (term); + + store->db_writable()->replace_document (docid, doc); if (store->inc_processed() % store->batch_size() == 0) store->commit_transaction(); @@ -679,7 +681,10 @@ mu_store_remove_path (MuStore *store, const char *msgpath) g_return_val_if_fail (msgpath, FALSE); try { - store->db_writable()->delete_document (store->get_uid_term (msgpath)); + const std::string term + (store->get_uid_term(msgpath)); + + store->db_writable()->delete_document (term); store->inc_processed(); return TRUE; diff --git a/src/mu-str.c b/src/mu-str.c index 664965de..4d0b223d 100644 --- a/src/mu-str.c +++ b/src/mu-str.c @@ -463,7 +463,7 @@ mu_str_ascii_xapian_escape_in_place (char *query) * a space'... ugh yuck ugly... */ if (!is_xapian_prefix (query, cur)) - *cur = '_'; + *cur = ' '; break; } } diff --git a/src/tests/test-mu-query.c b/src/tests/test-mu-query.c index 1eff2577..9850a10a 100644 --- a/src/tests/test-mu-query.c +++ b/src/tests/test-mu-query.c @@ -542,7 +542,7 @@ test_mu_query_tags_02 (void) { "x:paradise", 1}, { "tag:@NextActions", 1}, { "x:queensrÿche", 1}, - { "tag:lost OR tag:operation:mindcrime", 2}, + { "tag:lost OR tag:operation*", 2}, }; xpath = fill_database (MU_TESTMAILDIR2); @@ -605,4 +605,3 @@ main (int argc, char *argv[]) return rv; } - diff --git a/src/tests/test-mu-str.c b/src/tests/test-mu-str.c index 250a19e6..fea4ac74 100644 --- a/src/tests/test-mu-str.c +++ b/src/tests/test-mu-str.c @@ -1,6 +1,6 @@ /* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/ -/* +/* ** Copyright (C) 2008-2010 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify it @@ -15,8 +15,8 @@ ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** +** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** */ #if HAVE_CONFIG_H @@ -41,7 +41,7 @@ test_mu_str_size_01 (void) { struct lconv *lc; char *tmp2; - + lc = localeconv(); tmp2 = g_strdup_printf ("0%s0 kB", lc->decimal_point); @@ -57,18 +57,18 @@ test_mu_str_size_01 (void) g_free (tmp2); } - + static void test_mu_str_size_02 (void) { struct lconv *lc; char *tmp1, *tmp2; - + lc = localeconv(); - + tmp2 = g_strdup_printf ("1%s0 MB", lc->decimal_point); - tmp1 = mu_str_size (999999); + tmp1 = mu_str_size (999999); g_assert_cmpstr (tmp1, !=, tmp2); g_free (tmp1); @@ -101,7 +101,7 @@ test_mu_str_prio_02 (void) g_test_log_set_fatal_handler ((GTestLogFatalFunc)ignore_error, NULL); g_assert_cmpstr (mu_msg_prio_name(666), ==, NULL); } - + static void @@ -112,14 +112,14 @@ test_mu_str_normalize_01 (void) const char* word; const char* norm; } words [] = { - { "dantès", "dantes"}, + { "dantès", "dantes"}, { "foo", "foo" }, { "Föö", "foo" }, { "číslo", "cislo" }, { "hÆvý mëÐal ümláõt", "haevy medal umlaot"} }; - + for (i = 0; i != G_N_ELEMENTS(words); ++i) { gchar *str; str = mu_str_normalize (words[i].word, TRUE); @@ -137,14 +137,14 @@ test_mu_str_normalize_02 (void) const char* word; const char* norm; } words [] = { - { "DantèS", "DanteS"}, + { "DantèS", "DanteS"}, { "foo", "foo" }, { "Föö", "Foo" }, { "číslO", "cislO" }, { "hÆvý mëÐal ümláõt", "hAevy meDal umlaot"} }; - + for (i = 0; i != G_N_ELEMENTS(words); ++i) { gchar *str; str = mu_str_normalize (words[i].word, FALSE); @@ -162,14 +162,14 @@ test_mu_str_ascii_xapian_escape (void) const char* word; const char* esc; } words [] = { - { "aap@noot.mies", "aap_noot_mies"}, + { "aap@noot.mies", "aap_noot_mies"}, { "Foo..Bar", "foo..bar" }, { "Foo.Bar", "foo_bar" }, { "Foo. Bar", "foo. bar" }, { "subject:test@foo", "subject:test_foo" }, - { "xxx:test@bar", "xxx_test_bar" }, + { "xxx:test@bar", "xxx test_bar" }, }; - + for (i = 0; i != G_N_ELEMENTS(words); ++i) { gchar *a = g_strdup (words[i].word); mu_str_ascii_xapian_escape_in_place (a); @@ -187,14 +187,14 @@ test_mu_str_display_contact (void) const char* word; const char* disp; } words [] = { - { "\"Foo Bar\" ", "Foo Bar"}, + { "\"Foo Bar\" ", "Foo Bar"}, { "Foo Bar ", "Foo Bar" }, { "", "aap@noot.mies" }, { "foo@bar.nl", "foo@bar.nl" } }; - - for (i = 0; i != G_N_ELEMENTS(words); ++i) - g_assert_cmpstr (mu_str_display_contact_s (words[i].word), ==, + + for (i = 0; i != G_N_ELEMENTS(words); ++i) + g_assert_cmpstr (mu_str_display_contact_s (words[i].word), ==, words[i].disp); } @@ -204,10 +204,10 @@ assert_cmplst (GSList *lst, const char *items[]) { int i; - if (!lst) + if (!lst) g_assert (!items); - - for (i = 0; lst; lst = g_slist_next(lst), ++i) + + for (i = 0; lst; lst = g_slist_next(lst), ++i) g_assert_cmpstr ((char*)lst->data,==,items[i]); g_assert (items[i] == NULL); @@ -226,7 +226,7 @@ create_list (const char *items[]) } return g_slist_reverse (lst); - + } static void @@ -258,7 +258,7 @@ test_mu_str_from_list (void) mu_str_free_list (lst); g_free (str); } - + } @@ -298,7 +298,7 @@ static void test_mu_str_guess_first_name (void) { int i; - + struct { char *src, *exp; } tests[] = { @@ -307,7 +307,7 @@ test_mu_str_guess_first_name (void) { "Ivanhoe", "Ivanhoe" }, { "", "" } }; - + for (i = 0; i != G_N_ELEMENTS(tests); ++i) { gchar *s; @@ -322,7 +322,7 @@ static void test_mu_str_guess_last_name (void) { int i; - + struct { char *src, *exp; } tests[] = { @@ -331,7 +331,7 @@ test_mu_str_guess_last_name (void) { "Ivanhoe", "" }, { "", "" } }; - + for (i = 0; i != G_N_ELEMENTS(tests); ++i) { gchar *s; @@ -347,7 +347,7 @@ static void test_mu_str_guess_nick (void) { int i; - + struct { char *src, *exp; } tests[] = { @@ -356,7 +356,7 @@ test_mu_str_guess_nick (void) { "Ivanhoe", "Ivanhoe" }, { "", "" } }; - + for (i = 0; i != G_N_ELEMENTS(tests); ++i) { gchar *s; @@ -372,7 +372,7 @@ static void test_mu_str_subject_normalize (void) { int i; - + struct { char *src, *exp; } tests[] = { @@ -383,7 +383,7 @@ test_mu_str_subject_normalize (void) { "operation: mindcrime", "mindcrime" }, /*...*/ { "", "" } }; - + for (i = 0; i != G_N_ELEMENTS(tests); ++i) g_assert_cmpstr (mu_str_subject_normalize (tests[i].src), ==, tests[i].exp); @@ -421,15 +421,15 @@ main (int argc, char *argv[]) test_mu_str_ascii_xapian_escape); g_test_add_func ("/mu-str/mu-str-display_contact", - test_mu_str_display_contact); - + test_mu_str_display_contact); + 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); g_test_add_func ("/mu-str/mu-str-to-list-strip", test_mu_str_to_list_strip); - + g_test_add_func ("/mu-str/mu_str_guess_first_name", test_mu_str_guess_first_name); g_test_add_func ("/mu-str/mu_str_guess_last_name", @@ -443,10 +443,10 @@ main (int argc, char *argv[]) /* FIXME: add tests for mu_str_flags; but note the * function simply calls mu_msg_field_str */ - + g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION, (GLogFunc)black_hole, NULL); - + return g_test_run (); }