mirror of https://github.com/djcb/mu.git
* fix test-mu-cmd.c for stricter option checks
This commit is contained in:
parent
49077bf7d1
commit
6483e9d39e
|
@ -39,34 +39,34 @@
|
|||
static gchar*
|
||||
fill_database (void)
|
||||
{
|
||||
gchar *cmdline, *tmpdir;
|
||||
gchar *cmdline, *tmpdir;
|
||||
|
||||
tmpdir = test_mu_common_get_random_tmpdir();
|
||||
cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s"
|
||||
" --quiet",
|
||||
MU_PROGRAM, tmpdir, MU_TESTMAILDIR2);
|
||||
tmpdir = test_mu_common_get_random_tmpdir();
|
||||
cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s"
|
||||
" --quiet",
|
||||
MU_PROGRAM, tmpdir, MU_TESTMAILDIR2);
|
||||
|
||||
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL,
|
||||
NULL, NULL));
|
||||
g_free (cmdline);
|
||||
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL,
|
||||
NULL, NULL));
|
||||
g_free (cmdline);
|
||||
|
||||
return tmpdir;
|
||||
return tmpdir;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
newlines_in_output (const char* str)
|
||||
{
|
||||
int count;
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
count = 0;
|
||||
|
||||
while (str && *str) {
|
||||
if (*str == '\n')
|
||||
++count;
|
||||
++str;
|
||||
}
|
||||
|
||||
return count;
|
||||
while (str && *str) {
|
||||
if (*str == '\n')
|
||||
++count;
|
||||
++str;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -74,28 +74,28 @@ search (const char* query, unsigned expected)
|
|||
{
|
||||
gchar *muhome, *cmdline, *output, *erroutput;
|
||||
|
||||
muhome = fill_database ();
|
||||
g_assert (muhome);
|
||||
muhome = fill_database ();
|
||||
g_assert (muhome);
|
||||
|
||||
cmdline = g_strdup_printf ("%s --muhome=%s find %s",
|
||||
MU_PROGRAM, muhome, query);
|
||||
cmdline = g_strdup_printf ("%s find --muhome=%s %s",
|
||||
MU_PROGRAM, muhome, query);
|
||||
|
||||
/* g_printerr ("%s\n", cmdline); */
|
||||
/* g_printerr ("%s\n", cmdline); */
|
||||
|
||||
g_assert (g_spawn_command_line_sync (cmdline,
|
||||
&output, &erroutput,
|
||||
NULL, NULL));
|
||||
g_assert_cmpuint (newlines_in_output(output),==,expected);
|
||||
g_assert (g_spawn_command_line_sync (cmdline,
|
||||
&output, &erroutput,
|
||||
NULL, NULL));
|
||||
g_assert_cmpuint (newlines_in_output(output),==,expected);
|
||||
|
||||
/* we expect zero lines of error output if there is a match;
|
||||
* otherwise there should be one line 'No matches found' */
|
||||
/* g_assert_cmpuint (newlines_in_output(erroutput),==, */
|
||||
/* expected == 0 ? 1 : 0); */
|
||||
/* we expect zero lines of error output if there is a match;
|
||||
* otherwise there should be one line 'No matches found' */
|
||||
/* g_assert_cmpuint (newlines_in_output(erroutput),==, */
|
||||
/* expected == 0 ? 1 : 0); */
|
||||
|
||||
g_free (output);
|
||||
g_free (erroutput);
|
||||
g_free (cmdline);
|
||||
g_free (muhome);
|
||||
g_free (output);
|
||||
g_free (erroutput);
|
||||
g_free (cmdline);
|
||||
g_free (muhome);
|
||||
}
|
||||
|
||||
|
||||
|
@ -104,23 +104,22 @@ search (const char* query, unsigned expected)
|
|||
static void
|
||||
test_mu_index (void)
|
||||
{
|
||||
MuStore *store;
|
||||
gchar *muhome, *xpath;
|
||||
MuStore *store;
|
||||
gchar *muhome, *xpath;
|
||||
|
||||
muhome = fill_database ();
|
||||
g_assert (muhome != NULL);
|
||||
muhome = fill_database ();
|
||||
g_assert (muhome != NULL);
|
||||
|
||||
xpath = g_strdup_printf ("%s%c%s", muhome, G_DIR_SEPARATOR,
|
||||
"xapian");
|
||||
xpath = g_strdup_printf ("%s%c%s", muhome, G_DIR_SEPARATOR, "xapian");
|
||||
|
||||
store = mu_store_new (xpath, 0, NULL);
|
||||
g_assert (store);
|
||||
store = mu_store_new (xpath, 0, NULL);
|
||||
g_assert (store);
|
||||
|
||||
g_assert_cmpuint (mu_store_count (store), ==, 4);
|
||||
mu_store_destroy (store);
|
||||
g_assert_cmpuint (mu_store_count (store), ==, 4);
|
||||
mu_store_destroy (store);
|
||||
|
||||
g_free (muhome);
|
||||
g_free (xpath);
|
||||
g_free (muhome);
|
||||
g_free (xpath);
|
||||
}
|
||||
|
||||
|
||||
|
@ -128,15 +127,15 @@ test_mu_index (void)
|
|||
static void
|
||||
test_mu_find_01 (void)
|
||||
{
|
||||
search ("f:john fruit", 1);
|
||||
search ("f:soc@example.com", 1);
|
||||
search ("t:alki@example.com", 1);
|
||||
search ("t:alcibiades", 1);
|
||||
search ("f:soc@example.com OR f:john", 2);
|
||||
search ("f:soc@example.com OR f:john OR t:edmond", 3);
|
||||
search ("t:julius", 1);
|
||||
search ("s:dude", 1);
|
||||
search ("t:dantès", 1);
|
||||
search ("f:john fruit", 1);
|
||||
search ("f:soc@example.com", 1);
|
||||
search ("t:alki@example.com", 1);
|
||||
search ("t:alcibiades", 1);
|
||||
search ("f:soc@example.com OR f:john", 2);
|
||||
search ("f:soc@example.com OR f:john OR t:edmond", 3);
|
||||
search ("t:julius", 1);
|
||||
search ("s:dude", 1);
|
||||
search ("t:dantès", 1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -144,14 +143,14 @@ test_mu_find_01 (void)
|
|||
static void
|
||||
test_mu_find_02 (void)
|
||||
{
|
||||
search ("bull", 1);
|
||||
search ("bull m:foo", 0);
|
||||
search ("bull m:/foo", 1);
|
||||
search ("bull m:/Foo", 1);
|
||||
search ("bull flag:a", 1);
|
||||
search ("g:x", 0);
|
||||
search ("flag:encrypted", 0);
|
||||
search ("flag:attach", 1);
|
||||
search ("bull", 1);
|
||||
search ("bull m:foo", 0);
|
||||
search ("bull m:/foo", 1);
|
||||
search ("bull m:/Foo", 1);
|
||||
search ("bull flag:a", 1);
|
||||
search ("g:x", 0);
|
||||
search ("flag:encrypted", 0);
|
||||
search ("flag:attach", 1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -160,10 +159,10 @@ test_mu_find_02 (void)
|
|||
static void
|
||||
test_mu_find_03 (void)
|
||||
{
|
||||
search ("bull", 1);
|
||||
search ("bull m:foo", 0);
|
||||
search ("bull m:/foo", 1);
|
||||
search ("i:3BE9E6535E0D852173@emss35m06.us.lmco.com", 1);
|
||||
search ("bull", 1);
|
||||
search ("bull m:foo", 0);
|
||||
search ("bull m:/foo", 1);
|
||||
search ("i:3BE9E6535E0D852173@emss35m06.us.lmco.com", 1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -172,24 +171,24 @@ test_mu_find_04 (void)
|
|||
{
|
||||
gchar *muhome, *cmdline, *erroutput;
|
||||
|
||||
muhome = fill_database ();
|
||||
g_assert (muhome);
|
||||
muhome = fill_database ();
|
||||
g_assert (muhome);
|
||||
|
||||
cmdline = g_strdup_printf ("%s --muhome=%cfoo%cbar%cnonexistent find f:socrates",
|
||||
MU_PROGRAM,
|
||||
G_DIR_SEPARATOR,
|
||||
G_DIR_SEPARATOR,
|
||||
G_DIR_SEPARATOR);
|
||||
cmdline = g_strdup_printf ("%s --muhome=%cfoo%cbar%cnonexistent find f:socrates",
|
||||
MU_PROGRAM,
|
||||
G_DIR_SEPARATOR,
|
||||
G_DIR_SEPARATOR,
|
||||
G_DIR_SEPARATOR);
|
||||
|
||||
g_assert (g_spawn_command_line_sync (cmdline, NULL, &erroutput,
|
||||
NULL, NULL));
|
||||
g_assert (g_spawn_command_line_sync (cmdline, NULL, &erroutput,
|
||||
NULL, NULL));
|
||||
|
||||
/* we expect multiple lines of error output */
|
||||
g_assert_cmpuint (newlines_in_output(erroutput),>=,1);
|
||||
/* we expect multiple lines of error output */
|
||||
g_assert_cmpuint (newlines_in_output(erroutput),>=,1);
|
||||
|
||||
g_free (erroutput);
|
||||
g_free (cmdline);
|
||||
g_free (muhome);
|
||||
g_free (erroutput);
|
||||
g_free (cmdline);
|
||||
g_free (muhome);
|
||||
}
|
||||
|
||||
|
||||
|
@ -198,42 +197,42 @@ test_mu_extract_01 (void)
|
|||
{
|
||||
gchar *cmdline, *output, *erroutput;
|
||||
|
||||
cmdline = g_strdup_printf ("%s extract %s%cFoo%ccur%cmail4",
|
||||
MU_PROGRAM,
|
||||
MU_TESTMAILDIR2,
|
||||
G_DIR_SEPARATOR,
|
||||
G_DIR_SEPARATOR,
|
||||
G_DIR_SEPARATOR);
|
||||
cmdline = g_strdup_printf ("%s extract %s%cFoo%ccur%cmail4",
|
||||
MU_PROGRAM,
|
||||
MU_TESTMAILDIR2,
|
||||
G_DIR_SEPARATOR,
|
||||
G_DIR_SEPARATOR,
|
||||
G_DIR_SEPARATOR);
|
||||
|
||||
output = erroutput = NULL;
|
||||
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, NULL, NULL));
|
||||
g_assert_cmpstr (output,
|
||||
==,
|
||||
"MIME-parts in this message:\n"
|
||||
" 0 <none> multipart/mixed [<none>]\n"
|
||||
" 1 <none> text/plain [<none>]\n"
|
||||
" 2 sittingbull.jpg image/jpeg [inline]\n"
|
||||
" 3 custer.jpg image/jpeg [inline]\n");
|
||||
output = erroutput = NULL;
|
||||
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, NULL, NULL));
|
||||
g_assert_cmpstr (output,
|
||||
==,
|
||||
"MIME-parts in this message:\n"
|
||||
" 0 <none> multipart/mixed [<none>]\n"
|
||||
" 1 <none> text/plain [<none>]\n"
|
||||
" 2 sittingbull.jpg image/jpeg [inline]\n"
|
||||
" 3 custer.jpg image/jpeg [inline]\n");
|
||||
|
||||
/* we expect zero lines of error output */
|
||||
g_assert_cmpuint (newlines_in_output(erroutput),==,0);
|
||||
/* we expect zero lines of error output */
|
||||
g_assert_cmpuint (newlines_in_output(erroutput),==,0);
|
||||
|
||||
g_free (output);
|
||||
g_free (erroutput);
|
||||
g_free (cmdline);
|
||||
g_free (output);
|
||||
g_free (erroutput);
|
||||
g_free (cmdline);
|
||||
}
|
||||
|
||||
static gint64
|
||||
get_file_size (const char* path)
|
||||
{
|
||||
int rv;
|
||||
struct stat statbuf;
|
||||
int rv;
|
||||
struct stat statbuf;
|
||||
|
||||
rv = stat (path, &statbuf);
|
||||
if (rv != 0)
|
||||
return -1;
|
||||
rv = stat (path, &statbuf);
|
||||
if (rv != 0)
|
||||
return -1;
|
||||
|
||||
return (gint64)statbuf.st_size;
|
||||
return (gint64)statbuf.st_size;
|
||||
}
|
||||
|
||||
|
||||
|
@ -241,35 +240,35 @@ static void
|
|||
test_mu_extract_02 (void)
|
||||
{
|
||||
gchar *cmdline, *output, *tmpdir;
|
||||
gchar *att1, *att2;
|
||||
gchar *att1, *att2;
|
||||
|
||||
tmpdir = test_mu_common_get_random_tmpdir();
|
||||
tmpdir = test_mu_common_get_random_tmpdir();
|
||||
|
||||
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
||||
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
||||
|
||||
cmdline = g_strdup_printf ("%s extract -a --target-dir=%s %s%cFoo%ccur%cmail4",
|
||||
MU_PROGRAM,
|
||||
tmpdir,
|
||||
MU_TESTMAILDIR2,
|
||||
G_DIR_SEPARATOR,
|
||||
G_DIR_SEPARATOR,
|
||||
G_DIR_SEPARATOR);
|
||||
cmdline = g_strdup_printf ("%s extract -a --target-dir=%s %s%cFoo%ccur%cmail4",
|
||||
MU_PROGRAM,
|
||||
tmpdir,
|
||||
MU_TESTMAILDIR2,
|
||||
G_DIR_SEPARATOR,
|
||||
G_DIR_SEPARATOR,
|
||||
G_DIR_SEPARATOR);
|
||||
|
||||
output = NULL;
|
||||
g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL));
|
||||
g_assert_cmpstr (output, ==, "");
|
||||
output = NULL;
|
||||
g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL));
|
||||
g_assert_cmpstr (output, ==, "");
|
||||
|
||||
att1 = g_strdup_printf ("%s%ccuster.jpg", tmpdir, G_DIR_SEPARATOR);
|
||||
att2 = g_strdup_printf ("%s%csittingbull.jpg", tmpdir, G_DIR_SEPARATOR);
|
||||
att1 = g_strdup_printf ("%s%ccuster.jpg", tmpdir, G_DIR_SEPARATOR);
|
||||
att2 = g_strdup_printf ("%s%csittingbull.jpg", tmpdir, G_DIR_SEPARATOR);
|
||||
|
||||
g_assert_cmpint (get_file_size(att1),==,15960);
|
||||
g_assert_cmpint (get_file_size(att2),==,17674);
|
||||
g_assert_cmpint (get_file_size(att1),==,15960);
|
||||
g_assert_cmpint (get_file_size(att2),==,17674);
|
||||
|
||||
g_free (output);
|
||||
g_free (tmpdir);
|
||||
g_free (cmdline);
|
||||
g_free (att1);
|
||||
g_free (att2);
|
||||
g_free (output);
|
||||
g_free (tmpdir);
|
||||
g_free (cmdline);
|
||||
g_free (att1);
|
||||
g_free (att2);
|
||||
}
|
||||
|
||||
|
||||
|
@ -277,35 +276,35 @@ static void
|
|||
test_mu_extract_03 (void)
|
||||
{
|
||||
gchar *cmdline, *output, *tmpdir;
|
||||
gchar *att1, *att2;
|
||||
gchar *att1, *att2;
|
||||
|
||||
tmpdir = test_mu_common_get_random_tmpdir();
|
||||
tmpdir = test_mu_common_get_random_tmpdir();
|
||||
|
||||
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
||||
|
||||
cmdline = g_strdup_printf ("%s extract --parts 3 "
|
||||
"--target-dir=%s %s%cFoo%ccur%cmail4",
|
||||
MU_PROGRAM,
|
||||
tmpdir,
|
||||
MU_TESTMAILDIR2,
|
||||
G_DIR_SEPARATOR,
|
||||
G_DIR_SEPARATOR,
|
||||
G_DIR_SEPARATOR);
|
||||
output = NULL;
|
||||
g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL));
|
||||
g_assert_cmpstr (output, ==, "");
|
||||
|
||||
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
||||
att1 = g_strdup_printf ("%s%ccuster.jpg", tmpdir, G_DIR_SEPARATOR);
|
||||
att2 = g_strdup_printf ("%s%csittingbull.jpg", tmpdir, G_DIR_SEPARATOR);
|
||||
|
||||
cmdline = g_strdup_printf ("%s extract --parts 3 "
|
||||
"--target-dir=%s %s%cFoo%ccur%cmail4",
|
||||
MU_PROGRAM,
|
||||
tmpdir,
|
||||
MU_TESTMAILDIR2,
|
||||
G_DIR_SEPARATOR,
|
||||
G_DIR_SEPARATOR,
|
||||
G_DIR_SEPARATOR);
|
||||
output = NULL;
|
||||
g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL));
|
||||
g_assert_cmpstr (output, ==, "");
|
||||
|
||||
att1 = g_strdup_printf ("%s%ccuster.jpg", tmpdir, G_DIR_SEPARATOR);
|
||||
att2 = g_strdup_printf ("%s%csittingbull.jpg", tmpdir, G_DIR_SEPARATOR);
|
||||
g_assert_cmpint (get_file_size(att1),==,15960); /* should not exist */
|
||||
g_assert_cmpint (get_file_size(att2),==,-1);
|
||||
|
||||
g_assert_cmpint (get_file_size(att1),==,15960); /* should not exist */
|
||||
g_assert_cmpint (get_file_size(att2),==,-1);
|
||||
|
||||
g_free (output);
|
||||
g_free (tmpdir);
|
||||
g_free (cmdline);
|
||||
g_free (att1);
|
||||
g_free (att2);
|
||||
g_free (output);
|
||||
g_free (tmpdir);
|
||||
g_free (cmdline);
|
||||
g_free (att1);
|
||||
g_free (att2);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue