Permalink
Browse files

* updates for new APIs (mu-date.h)

  • Loading branch information...
1 parent 3c3f008 commit e39074319525c8977430c9186211724ced2afc5d @djcb djcb committed Jul 20, 2011
@@ -481,7 +481,7 @@ test_mu_view_multi (void)
len = strlen(output);
/* g_print ("\n[%s](%u)\n", output, len); */
- g_assert_cmpuint (len,==,164);
+ g_assert_cmpuint (len,==,162);
g_free (output);
g_free (cmdline);
@@ -517,7 +517,7 @@ test_mu_view_multi_separate (void)
len = strlen(output);
/* g_print ("\n[%s](%u)\n", output, len); */
- g_assert_cmpuint (len,==,166);
+ g_assert_cmpuint (len,==,164);
g_free (output);
g_free (cmdline);
@@ -45,7 +45,7 @@ fill_database (const char *testdir)
" --quiet",
MU_PROGRAM, tmpdir, testdir);
- /* g_printerr ("\n%s\n", cmdline); */
+ /* g_printerr ("\n%s\n", cmdline); */
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL,
NULL, NULL));
@@ -338,24 +338,77 @@ test_mu_query_wildcards (void)
}
+static const char*
+set_tz (const char* tz)
+{
+ static const char* oldtz;
+
+ oldtz = getenv ("TZ");
+ if (tz)
+ setenv ("TZ", tz, 1);
+ else
+ unsetenv ("TZ");
+
+ tzset ();
+ return oldtz;
+}
+
+
+static void
+test_mu_query_dates_helsinki (void)
+{
+ gchar *xpath;
+ int i;
+ const char *old_tz;
+
+
+ QResults queries[] = {
+ { "date:20080731..20080804", 5},
+ /* { "date:20080804..20080731", 5}, */
+ { "date:20080731..20080804", 5},
+ { "date:20080731..20080804 s:gcc", 1},
+ { "date:200808110803..now", 1},
+ { "date:200808110803..today", 1},
+ /* { "date:now..2008-08-11-08-03", 1}, */
+ /* { "date:today..2008-08-11-08-03", 1}, */
+ { "date:200808110801..now", 1},
+ };
+
+ old_tz = set_tz ("Europe/Helsinki");
+
+ xpath = fill_database (MU_TESTMAILDIR);
+ g_assert (xpath != NULL);
+
+ for (i = 0; i != G_N_ELEMENTS(queries); ++i)
+ g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
+ ==, queries[i].count);
+
+ g_free (xpath);
+ set_tz (old_tz);
+
+}
static void
-test_mu_query_dates (void)
+test_mu_query_dates_sydney (void)
{
gchar *xpath;
int i;
+ const char *old_tz;
+
QResults queries[] = {
{ "date:20080731..20080804", 5},
/* { "date:20080804..20080731", 5}, */
- { "date:2008-07/31..2008@08:04", 5},
- { "date:2008-0731..20080804 s:gcc", 1},
- { "date:2008-08-11-08-03..now", 1},
- { "date:2008-08-11-08-03..today", 1},
+ { "date:20080731..20080804", 5},
+ { "date:20080731..20080804 s:gcc", 1},
+ { "date:200808110803..now", 1},
+ { "date:200808110803..today", 1},
/* { "date:now..2008-08-11-08-03", 1}, */
/* { "date:today..2008-08-11-08-03", 1}, */
- { "date:2008-08-11-08-05..now", 0},
+ { "date:200808110801..now", 1},
};
+
+ old_tz = set_tz ("Australia/Sydney");
xpath = fill_database (MU_TESTMAILDIR);
g_assert (xpath != NULL);
@@ -365,9 +418,44 @@ test_mu_query_dates (void)
==, queries[i].count);
g_free (xpath);
+ set_tz (old_tz);
}
+static void
+test_mu_query_dates_la (void)
+{
+ gchar *xpath;
+ int i;
+ const char *old_tz;
+
+ QResults queries[] = {
+ { "date:20080731..20080804", 5},
+ /* { "date:20080804..20080731", 5}, */
+ { "date:20080731..20080804", 5},
+ { "date:20080731..20080804 s:gcc", 1},
+ { "date:200808110803..now", 0},
+ { "date:200808110803..today", 0},
+ /* { "date:now..2008-08-11-08-03", 1}, */
+ /* { "date:today..2008-08-11-08-03", 1}, */
+ { "date:200808110801..now", 0}, /* does not match in LA */
+ };
+
+ old_tz = set_tz ("America/Los_Angeles");
+
+ xpath = fill_database (MU_TESTMAILDIR);
+ g_assert (xpath != NULL);
+
+ for (i = 0; i != G_N_ELEMENTS(queries); ++i)
+ g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
+ ==, queries[i].count);
+
+ g_free (xpath);
+ set_tz (old_tz);
+}
+
+
+
static void
test_mu_query_sizes (void)
@@ -483,6 +571,7 @@ main (int argc, char *argv[])
int rv;
g_test_init (&argc, &argv, NULL);
+
g_test_add_func ("/mu-query/test-mu-query-01", test_mu_query_01);
g_test_add_func ("/mu-query/test-mu-query-02", test_mu_query_02);
g_test_add_func ("/mu-query/test-mu-query-03", test_mu_query_03);
@@ -495,8 +584,14 @@ main (int argc, char *argv[])
test_mu_query_wildcards);
g_test_add_func ("/mu-query/test-mu-query-sizes",
test_mu_query_sizes);
- g_test_add_func ("/mu-query/test-mu-query-dates",
- test_mu_query_dates);
+
+ g_test_add_func ("/mu-query/test-mu-query-dates-helsinki",
+ test_mu_query_dates_helsinki); /* finland */
+ g_test_add_func ("/mu-query/test-mu-query-dates-sydney",
+ test_mu_query_dates_sydney);
+ g_test_add_func ("/mu-query/test-mu-query-dates-la",
+ test_mu_query_dates_la);
+
g_test_add_func ("/mu-query/test-mu-query-attach",
test_mu_query_attach);
g_test_add_func ("/mu-query/test-mu-query-tags",
@@ -34,31 +34,6 @@
#include "src/mu-str.h"
#include "src/mu-msg-prio.h"
-static void
-test_mu_str_date_01 (void)
-{
- struct tm *tmbuf;
- char buf[64];
- gchar *tmp;
- time_t some_time;
-
- some_time = 1234567890;
- tmbuf = localtime (&some_time);
- strftime (buf, 64, "%x", tmbuf);
-
- /* $ date -ud@1234567890; Fri Feb 13 23:31:30 UTC 2009 */
- g_assert_cmpstr (mu_str_date_s ("%x", some_time), ==, buf);
-
- /* date -ud@987654321 Thu Apr 19 04:25:21 UTC 2001 */
- some_time = 987654321;
- tmbuf = localtime (&some_time);
- strftime (buf, 64, "%c", tmbuf);
- tmp = mu_str_date ("%c", some_time);
-
- g_assert_cmpstr (tmp, ==, buf);
- g_free (tmp);
-
-}
static void
@@ -224,37 +199,6 @@ test_mu_str_display_contact (void)
}
-
-static void
-test_mu_str_date_parse_hdwmy (void)
-{
- time_t diff;
-
- diff = time(NULL) - mu_str_date_parse_hdwmy ("3h");
- g_assert (diff > 0);
- g_assert_cmpuint (3 * 60 * 60 - diff, <=, 1);
-
- diff = time(NULL) - mu_str_date_parse_hdwmy ("5y");
- g_assert (diff > 0);
- g_assert_cmpuint (5 * 365 * 24 * 60 * 60 - diff, <=, 1);
-
- diff = time(NULL) - mu_str_date_parse_hdwmy ("3m");
- g_assert (diff > 0);
- g_assert_cmpuint (3 * 30 * 24 * 60 * 60 - diff, <=, 1);
-
- diff = time(NULL) - mu_str_date_parse_hdwmy ("21d");
- g_assert (diff > 0);
- g_assert_cmpuint (21 * 24 * 60 * 60 - diff, <=, 1);
-
- diff = time(NULL) - mu_str_date_parse_hdwmy ("2w");
- g_assert (diff > 0);
- g_assert_cmpuint (2 * 7 * 24 * 60 * 60 - diff, <=, 1);
-
-
- g_assert_cmpint (mu_str_date_parse_hdwmy("-1y"),==, (time_t)-1);
-}
-
-
static void
assert_cmplst (GSList *lst, const char *items[])
{
@@ -454,9 +398,6 @@ main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
- /* mu_str_date */
- g_test_add_func ("/mu-str/mu-str-date",
- test_mu_str_date_01);
/* mu_str_size */
g_test_add_func ("/mu-str/mu-str-size-01",
@@ -489,9 +430,6 @@ main (int argc, char *argv[])
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_date_parse_hdwmy",
- test_mu_str_date_parse_hdwmy);
-
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",
@@ -21,7 +21,7 @@
#include "mug-msg-list-view.h"
#include "mu-query.h"
#include "mu-str.h"
-/* include other impl specific header files */
+#include "mu-date.h"
/* 'private'/'protected' functions */
static void mug_msg_list_view_class_init (MugMsgListViewClass * klass);
@@ -359,7 +359,7 @@ add_row (GtkListStore * store, MuMsg *msg)
time_t timeval;
timeval = mu_msg_get_date (msg);
- datestr = timeval == 0 ? "-" : mu_str_display_date_s (timeval);
+ datestr = timeval == 0 ? "-" : mu_date_display_s (timeval);
from = empty_or_display_contact (mu_msg_get_from (msg));
to = empty_or_display_contact (mu_msg_get_to (msg));
flagstr = mu_msg_flags_str_s (mu_msg_get_flags (msg));
@@ -20,6 +20,7 @@
#include "mug-msg-view.h"
#include "mu-msg.h"
#include "mu-str.h"
+#include "mu-date.h"
/* 'private'/'protected' functions */
static void mug_msg_view_class_init (MugMsgViewClass * klass);
@@ -257,7 +258,7 @@ fill_header (MugMsgViewPrivate * priv, MuMsg * msg)
case HEADER_ROW_CC: val = mu_msg_get_cc (msg); break;
case HEADER_ROW_PATH: val = mu_msg_get_path (msg); break;
case HEADER_ROW_DATE:
- val = mu_str_date_s ("%c", mu_msg_get_date (msg));
+ val = mu_date_str_s ("%c", mu_msg_get_date (msg));
break;
case HEADER_ROW_SIZE:
val = mu_str_size_s (mu_msg_get_size (msg));
@@ -21,6 +21,7 @@
#include "mug-msg-list-view.h"
#include "mu-query.h"
#include "mu-str.h"
+#include "mu-date.h"
#include "mu-threader.h"
/* 'private'/'protected' functions */
@@ -360,7 +361,7 @@ add_row (GtkTreeStore * store, MuMsg *msg, GtkTreeIter *treeiter)
time_t timeval;
timeval = mu_msg_get_date (msg);
- datestr = timeval == 0 ? "-" : mu_str_display_date_s (timeval);
+ datestr = timeval == 0 ? "-" : mu_date_display_s (timeval);
from = empty_or_display_contact (mu_msg_get_from (msg));
to = empty_or_display_contact (mu_msg_get_to (msg));
flagstr = mu_msg_flags_str_s (mu_msg_get_flags (msg));
@@ -18,7 +18,9 @@
*/
#include "mu-msg-header-view.h"
+
#include <mu-str.h>
+#include <mu-date.h>
/* 'private'/'protected' functions */
static void mu_msg_header_view_class_init (MuMsgHeaderViewClass *klass);
@@ -155,7 +157,7 @@ get_table (MuMsg *msg)
++row;
if (add_row (table, row, "Subject", mu_msg_get_subject (msg), TRUE))
++row;
- if (add_row (table, row, "Date", mu_str_date_s
+ if (add_row (table, row, "Date", mu_date_str_s
("%c", mu_msg_get_date (msg)),TRUE))
++row;

0 comments on commit e390743

Please sign in to comment.