* updates for new APIs (mu-date.h)
This commit is contained in:
@ -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,43 @@ 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 (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: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 ("Europe/Helsinki");
|
||||
|
||||
xpath = fill_database (MU_TESTMAILDIR);
|
||||
g_assert (xpath != NULL);
|
||||
@ -365,9 +384,78 @@ test_mu_query_dates (void)
|
||||
==, queries[i].count);
|
||||
|
||||
g_free (xpath);
|
||||
set_tz (old_tz);
|
||||
|
||||
}
|
||||
|
||||
static 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: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 ("Australia/Sydney");
|
||||
|
||||
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_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",
|
||||
|
||||
Reference in New Issue
Block a user