mirror of https://github.com/djcb/mu.git
* fix mu_msg_field_type_is_numeric + unit test
This commit is contained in:
parent
f77e843cde
commit
c688cad8fc
|
@ -165,7 +165,7 @@ static const MuMsgField* mu_msg_field (MuMsgFieldId id)
|
||||||
|
|
||||||
/* initialize the array, but only once... */
|
/* initialize the array, but only once... */
|
||||||
if (G_UNLIKELY(!_initialized)) {
|
if (G_UNLIKELY(!_initialized)) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i != G_N_ELEMENTS(FIELD_DATA); ++i)
|
for (i = 0; i != G_N_ELEMENTS(FIELD_DATA); ++i)
|
||||||
_msg_field_data[FIELD_DATA[i]._id] =
|
_msg_field_data[FIELD_DATA[i]._id] =
|
||||||
(MuMsgField*)&FIELD_DATA[i];
|
(MuMsgField*)&FIELD_DATA[i];
|
||||||
|
@ -221,7 +221,6 @@ mu_msg_field_id_from_shortcut (char kar, gboolean err)
|
||||||
gboolean
|
gboolean
|
||||||
mu_msg_field_gmime (MuMsgFieldId id)
|
mu_msg_field_gmime (MuMsgFieldId id)
|
||||||
{
|
{
|
||||||
|
|
||||||
g_return_val_if_fail (mu_msg_field_id_is_valid(id),FALSE);
|
g_return_val_if_fail (mu_msg_field_id_is_valid(id),FALSE);
|
||||||
return mu_msg_field(id)->_flags & FLAG_GMIME;
|
return mu_msg_field(id)->_flags & FLAG_GMIME;
|
||||||
}
|
}
|
||||||
|
@ -259,11 +258,15 @@ mu_msg_field_xapian_contact (MuMsgFieldId id)
|
||||||
gboolean
|
gboolean
|
||||||
mu_msg_field_is_numeric (MuMsgFieldId mfid)
|
mu_msg_field_is_numeric (MuMsgFieldId mfid)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (mu_msg_field_id_is_valid(mfid),FALSE);
|
MuMsgFieldType type;
|
||||||
|
|
||||||
return mfid == MU_MSG_FIELD_TYPE_BYTESIZE ||
|
g_return_val_if_fail (mu_msg_field_id_is_valid(mfid),FALSE);
|
||||||
mfid == MU_MSG_FIELD_TYPE_TIME_T ||
|
|
||||||
mfid == MU_MSG_FIELD_TYPE_INT;
|
type = mu_msg_field_type (mfid);
|
||||||
|
|
||||||
|
return type == MU_MSG_FIELD_TYPE_BYTESIZE ||
|
||||||
|
type == MU_MSG_FIELD_TYPE_TIME_T ||
|
||||||
|
type == MU_MSG_FIELD_TYPE_INT;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
|
|
|
@ -203,6 +203,11 @@ gint64
|
||||||
mu_msg_iter_get_field_numeric (MuMsgIter *iter, MuMsgFieldId mfid)
|
mu_msg_iter_get_field_numeric (MuMsgIter *iter, MuMsgFieldId mfid)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (!mu_msg_iter_is_done(iter), -1);
|
g_return_val_if_fail (!mu_msg_iter_is_done(iter), -1);
|
||||||
|
|
||||||
|
if (!mu_msg_field_is_numeric(mfid))
|
||||||
|
g_printerr ("%s: %s\n", __FUNCTION__,
|
||||||
|
mu_msg_field_name (mfid));
|
||||||
|
|
||||||
g_return_val_if_fail (mu_msg_field_is_numeric(mfid), -1);
|
g_return_val_if_fail (mu_msg_field_is_numeric(mfid), -1);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -0,0 +1,136 @@
|
||||||
|
/*
|
||||||
|
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
|
**
|
||||||
|
** 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,
|
||||||
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif /*HAVE_CONFIG_H*/
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
|
#include "test-mu-common.h"
|
||||||
|
#include "src/mu-msg-fields.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_mu_msg_field_body (void)
|
||||||
|
{
|
||||||
|
MuMsgFieldId field;
|
||||||
|
|
||||||
|
field = MU_MSG_FIELD_ID_BODY_TEXT;
|
||||||
|
|
||||||
|
g_assert_cmpstr (mu_msg_field_name(field),==, "body");
|
||||||
|
g_assert_cmpuint (mu_msg_field_shortcut(field),==, 'b');
|
||||||
|
g_assert_cmpuint (mu_msg_field_xapian_prefix(field),==, 'B');
|
||||||
|
|
||||||
|
g_assert_cmpuint (mu_msg_field_is_numeric(field), ==, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_mu_msg_field_subject (void)
|
||||||
|
{
|
||||||
|
MuMsgFieldId field;
|
||||||
|
|
||||||
|
field = MU_MSG_FIELD_ID_SUBJECT;
|
||||||
|
|
||||||
|
g_assert_cmpstr (mu_msg_field_name(field),==, "subject");
|
||||||
|
g_assert_cmpuint (mu_msg_field_shortcut(field),==, 's');
|
||||||
|
g_assert_cmpuint (mu_msg_field_xapian_prefix(field),==, 'S');
|
||||||
|
|
||||||
|
g_assert_cmpuint (mu_msg_field_is_numeric(field), ==,FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_mu_msg_field_to (void)
|
||||||
|
{
|
||||||
|
MuMsgFieldId field;
|
||||||
|
|
||||||
|
field = MU_MSG_FIELD_ID_TO;
|
||||||
|
|
||||||
|
g_assert_cmpstr (mu_msg_field_name(field),==, "to");
|
||||||
|
g_assert_cmpuint (mu_msg_field_shortcut(field),==, 't');
|
||||||
|
g_assert_cmpuint (mu_msg_field_xapian_prefix(field),==, 'T');
|
||||||
|
|
||||||
|
g_assert_cmpuint (mu_msg_field_is_numeric(field), ==, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_mu_msg_field_prio (void)
|
||||||
|
{
|
||||||
|
MuMsgFieldId field;
|
||||||
|
|
||||||
|
field = MU_MSG_FIELD_ID_PRIO;
|
||||||
|
|
||||||
|
g_assert_cmpstr (mu_msg_field_name(field),==, "prio");
|
||||||
|
g_assert_cmpuint (mu_msg_field_shortcut(field),==, 'p');
|
||||||
|
g_assert_cmpuint (mu_msg_field_xapian_prefix(field),==, 'P');
|
||||||
|
|
||||||
|
g_assert_cmpuint (mu_msg_field_is_numeric(field), ==, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_mu_msg_field_flags (void)
|
||||||
|
{
|
||||||
|
MuMsgFieldId field;
|
||||||
|
|
||||||
|
field = MU_MSG_FIELD_ID_FLAGS;
|
||||||
|
|
||||||
|
g_assert_cmpstr (mu_msg_field_name(field),==, "flags");
|
||||||
|
g_assert_cmpuint (mu_msg_field_shortcut(field),==, 'g');
|
||||||
|
g_assert_cmpuint (mu_msg_field_xapian_prefix(field),==, 'G');
|
||||||
|
|
||||||
|
g_assert_cmpuint (mu_msg_field_is_numeric(field),==, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
|
/* mu_msg_str_date */
|
||||||
|
g_test_add_func ("/mu-msg-fields/mu-msg-field-body",
|
||||||
|
test_mu_msg_field_body);
|
||||||
|
g_test_add_func ("/mu-msg-fields/mu-msg-field-subject",
|
||||||
|
test_mu_msg_field_subject);
|
||||||
|
g_test_add_func ("/mu-msg-fields/mu-msg-field-to",
|
||||||
|
test_mu_msg_field_to);
|
||||||
|
g_test_add_func ("/mu-msg-fields/mu-msg-field-prio",
|
||||||
|
test_mu_msg_field_prio);
|
||||||
|
g_test_add_func ("/mu-msg-fields/mu-msg-field-flags",
|
||||||
|
test_mu_msg_field_flags);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* FIXME: add tests for mu_msg_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 ();
|
||||||
|
}
|
Loading…
Reference in New Issue