mirror of https://github.com/djcb/mu.git
* tests/: update unit tests
This commit is contained in:
parent
64985d7791
commit
a5db0a6d81
|
@ -85,4 +85,6 @@ EXTRA_DIST= \
|
|||
testdir/cur/1220863060.12663_3.mindcrime!2,S \
|
||||
testdir/cur/1283599333.1840_11.cthulhu!2, \
|
||||
testdir2/bar/cur/mail1 \
|
||||
testdir2/bar/cur/mail2
|
||||
testdir2/bar/cur/mail2 \
|
||||
testdir2/bar/cur/mail3
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
static gchar*
|
||||
fill_database (void)
|
||||
{
|
||||
gchar *cmdline, *tmpdir, *xpath;
|
||||
gchar *cmdline, *tmpdir;
|
||||
|
||||
tmpdir = test_mu_common_get_random_tmpdir();
|
||||
cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s"
|
||||
|
@ -47,31 +47,114 @@ fill_database (void)
|
|||
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, NULL, NULL));
|
||||
g_free (cmdline);
|
||||
|
||||
xpath = g_strdup_printf ("%s%c%s", tmpdir, G_DIR_SEPARATOR, "xapian");
|
||||
g_free (tmpdir);
|
||||
return tmpdir;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
newlines_in_output (const char* str)
|
||||
{
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
|
||||
while (str && *str) {
|
||||
if (*str == '\n')
|
||||
++count;
|
||||
++str;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static void
|
||||
search (const char* query, unsigned expected)
|
||||
{
|
||||
gchar *muhome, *cmdline, *output, *erroutput;
|
||||
|
||||
muhome = fill_database ();
|
||||
g_assert (muhome);
|
||||
|
||||
cmdline = g_strdup_printf ("%s --muhome=%s find %s",
|
||||
MU_PROGRAM, muhome, query);
|
||||
|
||||
return xpath;
|
||||
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 */
|
||||
g_assert_cmpuint (newlines_in_output(erroutput),==,0);
|
||||
|
||||
g_free (output);
|
||||
g_free (erroutput);
|
||||
g_free (cmdline);
|
||||
g_free (muhome);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* index testdir2, and make sure it adds two documents */
|
||||
static void
|
||||
test_mu_index (void)
|
||||
{
|
||||
MuStore *store;
|
||||
gchar *xpath;
|
||||
gchar *muhome, *xpath;
|
||||
|
||||
xpath = fill_database ();
|
||||
g_assert (xpath != NULL);
|
||||
muhome = fill_database ();
|
||||
g_assert (muhome != NULL);
|
||||
|
||||
xpath = g_strdup_printf ("%s%c%s", muhome, G_DIR_SEPARATOR, "xapian");
|
||||
|
||||
store = mu_store_new (xpath);
|
||||
g_assert (store);
|
||||
|
||||
g_assert_cmpuint (mu_store_count (store), ==, 2);
|
||||
g_assert_cmpuint (mu_store_count (store), ==, 3);
|
||||
mu_store_destroy (store);
|
||||
|
||||
g_free (muhome);
|
||||
g_free (xpath);
|
||||
}
|
||||
|
||||
|
||||
/* index testdir2, and make sure it adds two documents */
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
static void /* error cases */
|
||||
test_mu_find_02 (void)
|
||||
{
|
||||
gchar *muhome, *cmdline, *erroutput;
|
||||
|
||||
muhome = fill_database ();
|
||||
g_assert (muhome);
|
||||
|
||||
cmdline = g_strdup_printf ("%s --muhome=/foo/bar/nonexistent find f:socrates",
|
||||
MU_PROGRAM);
|
||||
|
||||
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);
|
||||
|
||||
g_free (erroutput);
|
||||
g_free (cmdline);
|
||||
g_free (muhome);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
|
@ -79,8 +162,8 @@ main (int argc, char *argv[])
|
|||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/mu-cmd/test-mu-index", test_mu_index);
|
||||
// g_test_add_func ("/mu-cmd/test-mu-find", test_mu_find_01);
|
||||
// g_test_add_func ("/mu-cmd/test-mu-find", test_mu_find_02);
|
||||
g_test_add_func ("/mu-cmd/test-mu-find-01", test_mu_find_01);
|
||||
g_test_add_func ("/mu-cmd/test-mu-find-02", test_mu_find_02);
|
||||
|
||||
g_log_set_handler (NULL,
|
||||
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
||||
|
|
|
@ -1,12 +1,36 @@
|
|||
Date: Thu, 31 Jul 2008 14:57:25 -0400
|
||||
From: "Mickey Mouse" <anon@example.com>
|
||||
Subject: a mail about avians
|
||||
To: "John Smith" <smith@example.com>
|
||||
From: "John Milton" <jm@example.com>
|
||||
Subject: Fere libenter homines id quod volunt credunt
|
||||
To: "Julius Caesar" <jc@example.com>
|
||||
Message-id: <3BE9E6535E3029448670913581E7A1A20D852173@emss35m06.us.lmco.com>
|
||||
MIME-version: 1.0
|
||||
Content-type: text/plain; charset=us-ascii
|
||||
Content-transfer-encoding: 7BIT
|
||||
Precedence: high
|
||||
|
||||
This is a mail about birds.
|
||||
|
||||
OF Mans First Disobedience, and the Fruit
|
||||
Of that Forbidden Tree, whose mortal tast
|
||||
Brought Death into the World, and all our woe,
|
||||
With loss of Eden, till one greater Man
|
||||
Restore us, and regain the blissful Seat, [ 5 ]
|
||||
Sing Heav'nly Muse,that on the secret top
|
||||
Of Oreb, or of Sinai, didst inspire
|
||||
That Shepherd, who first taught the chosen Seed,
|
||||
In the Beginning how the Heav'ns and Earth
|
||||
Rose out of Chaos: Or if Sion Hill [ 10 ]
|
||||
Delight thee more, and Siloa's Brook that flow'd
|
||||
Fast by the Oracle of God; I thence
|
||||
Invoke thy aid to my adventrous Song,
|
||||
That with no middle flight intends to soar
|
||||
Above th' Aonian Mount, while it pursues [ 15 ]
|
||||
Things unattempted yet in Prose or Rhime.
|
||||
And chiefly Thou O Spirit, that dost prefer
|
||||
Before all Temples th' upright heart and pure,
|
||||
Instruct me, for Thou know'st; Thou from the first
|
||||
Wast present, and with mighty wings outspread [ 20 ]
|
||||
Dove-like satst brooding on the vast Abyss
|
||||
And mad'st it pregnant: What in me is dark
|
||||
Illumin, what is low raise and support;
|
||||
That to the highth of this great Argument
|
||||
I may assert Eternal Providence, [ 25 ]
|
||||
And justifie the wayes of God to men.
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
Date: Thu, 31 Jul 2008 14:57:25 -0400
|
||||
From: "Kaspar Hauser" <kaspar@example.com>
|
||||
Subject: a mail about south-american mammals
|
||||
To: "William Jones" <jones@example.com>
|
||||
From: "Socrates" <soc@example.com>
|
||||
Subject: cool stuff
|
||||
To: "Alcibiades" <alki@example.com>
|
||||
Message-id: <3BE9E6535E0D852173@emss35m06.us.lmco.com>
|
||||
MIME-version: 1.0
|
||||
Content-type: text/plain; charset=us-ascii
|
||||
Content-transfer-encoding: 7BIT
|
||||
Precedence: high
|
||||
|
||||
Capibaras are cute animals.
|
||||
The hour of departure has arrived, and we go our ways—I to die, and you to
|
||||
live. Which is better God only knows.
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
From: Napoleon Bonaparte <nb@example.com>
|
||||
To: Edmond =?UTF-8?B?RGFudMOocw==?= <ed@example.com>
|
||||
Subject: rock on dude
|
||||
User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/24.0 Mule/6.0 (HANACHIRUSATO)
|
||||
Fcc: .sent
|
||||
MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka")
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
|
||||
Le 24 février 1815, la vigie de Notre-Dame de la Garde signala le trois-mâts
|
||||
le Pharaon, venant de Smyrne, Trieste et Naples.
|
||||
|
||||
Comme d'habitude, un pilote côtier partit aussitôt du port, rasa le château
|
||||
d'If, et alla aborder le navire entre le cap de Morgion et l'île de Rion.
|
||||
|
||||
Aussitôt, comme d'habitude encore, la plate-forme du fort Saint-Jean s'était
|
||||
couverte de curieux; car c'est toujours une grande affaire à Marseille que
|
||||
l'arrivée d'un bâtiment, surtout quand ce bâtiment, comme le Pharaon, a été
|
||||
construit, gréé, arrimé sur les chantiers de la vieille Phocée, et appartient
|
||||
à un armateur de la ville.
|
||||
|
||||
Cependant ce bâtiment s'avançait; il avait heureusement franchi le détroit que
|
||||
quelque secousse volcanique a creusé entre l'île de Calasareigne et l'île de
|
||||
Jaros; il avait doublé Pomègue, et il s'avançait sous ses trois huniers, son
|
||||
grand foc et sa brigantine, mais si lentement et d'une allure si triste, que
|
||||
les curieux, avec cet instinct qui pressent un malheur, se demandaient quel
|
||||
accident pouvait être arrivé à bord. Néanmoins les experts en navigation
|
||||
reconnaissaient que si un accident était arrivé, ce ne pouvait être au
|
||||
bâtiment lui-même; car il s'avançait dans toutes les conditions d'un navire
|
||||
parfaitement gouverné: son ancre était en mouillage, ses haubans de beaupré
|
||||
décrochés; et près du pilote, qui s'apprêtait à diriger le Pharaon par
|
||||
l'étroite entrée du port de Marseille, était un jeune homme au geste rapide et
|
||||
à l'œil actif, qui surveillait chaque mouvement du navire et répétait chaque
|
||||
ordre du pilote.
|
Loading…
Reference in New Issue