Commit 26ae64a3 authored by Richard P. Curnow's avatar Richard P. Curnow

Add test suite

This was very generously sent to me by an anonymous benefactor.
parent 0a078722
......@@ -14,6 +14,4 @@ make.log
nvpscan.c
nvpscan.h
nvp.report
test
test_*
version.h
......@@ -85,8 +85,10 @@ clean:
-rm -f fromcheck.[ch] datescan.[ch]
-rm -f nvpscan.[ch]
if [ -d dfasyn ]; then cd dfasyn ; $(MAKE) clean ; fi
if [ -d test ]; then cd test ; $(MAKE) clean ; fi
distclean: clean
if [ -d test ]; then cd test ; $(MAKE) distclean ; fi
-rm -f Makefile config.log
install:
......@@ -102,7 +104,10 @@ install:
cp -f mairixrc.5 $(man5dir)
chmod 444 $(man5dir)/mairixrc.5
.PHONY : all install clean distclean
check: mairix
if [ -d test ]; then cd test ; $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" check ; else echo "No test subdirectory?" ; exit 1 ; fi
.PHONY : all install clean distclean check
mairix.o : version.h
......
......@@ -186,7 +186,7 @@ void check_database_integrity(struct database *db)/*{{{*/
check_toktable_enc_integrity(db->n_msgs, db->attachment_name);
}
/*}}}*/
struct database *new_database(void)/*{{{*/
struct database *new_database(unsigned int hash_key)/*{{{*/
{
struct database *result = new(struct database);
struct timeval tv;
......@@ -201,9 +201,13 @@ struct database *new_database(void)/*{{{*/
result->msg_ids = new_toktable2();
gettimeofday(&tv, NULL);
pid = getpid();
result->hash_key = tv.tv_sec ^ (pid ^ (tv.tv_usec << 15));
if ( hash_key == CREATE_RANDOM_DATABASE_HASH )
{
gettimeofday(&tv, NULL);
pid = getpid();
hash_key = tv.tv_sec ^ (pid ^ (tv.tv_usec << 15));
}
result->hash_key = hash_key;
result->msgs = NULL;
result->type = NULL;
......@@ -413,7 +417,7 @@ struct database *new_database_from_file(char *db_filename, int do_integrity_chec
struct read_db *input;
int i, n, N;
result = new_database();
result = new_database( CREATE_RANDOM_DATABASE_HASH );
input = open_db(db_filename);
if (!input) {
/* Nothing to initialise */
......
......@@ -37,17 +37,15 @@
#include "reader.h"
#include "memmac.h"
static void dump_toktable(struct read_db *db, struct toktable_db *tbl, const char *title)
static void dump_token_chain(struct read_db *db, unsigned int n, unsigned int *tok_offsets, unsigned int *enc_offsets)
{
int i, n, j, incr;
int i, j, incr;
int on_line;
unsigned char *foo;
printf("Contents of <%s> table\n", title);
n = tbl->n;
printf("%d entries\n", n);
for (i=0; i<n; i++) {
printf("Word %d : <%s>\n", i, db->data + tbl->tok_offsets[i]);
foo = (unsigned char *) db->data + tbl->enc_offsets[i];
printf("Word %d : <%s>\n", i, db->data + tok_offsets[i]);
foo = (unsigned char *) db->data + enc_offsets[i];
j = 0;
on_line = 0;
printf(" ");
......@@ -65,6 +63,23 @@ static void dump_toktable(struct read_db *db, struct toktable_db *tbl, const cha
}
}
static void dump_toktable(struct read_db *db, struct toktable_db *tbl, const char *title)
{
printf("Contents of <%s> table\n", title);
dump_token_chain( db, tbl->n, tbl->tok_offsets, tbl->enc_offsets);
}
static void dump_toktable2(struct read_db *db, struct toktable2_db *tbl, const char *title)
{
unsigned int n;
n = tbl->n;
printf("Contents of <%s> table\n", title);
printf("Chain 0\n");
dump_token_chain( db, n, tbl->tok_offsets, tbl->enc0_offsets);
printf("Chain 1\n");
dump_token_chain( db, n, tbl->tok_offsets, tbl->enc1_offsets);
}
void dump_database(char *filename)
{
struct read_db *db;
......@@ -127,6 +142,8 @@ void dump_database(char *filename)
printf("--------------------------------\n");
dump_toktable(db, &db->attachment_name, "Attachment names");
printf("--------------------------------\n");
dump_toktable2(db, &db->msg_ids, "Message Ids");
printf("--------------------------------\n");
close_db(db);
return;
......
......@@ -39,6 +39,9 @@ mairix \- index and search mail folders
.I mairixrc
] [
.BR \-F | \-\-fast-index
] [
.BR \-\-force-hash-key-new-database
.I hash
]
.SS Searching
......@@ -197,6 +200,15 @@ in the database, it should assume the message is unchanged.
A later indexing run without using this option will fix up any rescans that
were missed due to its use.
.TP
.BI "--force-hash-key-new-database " hash
.br
This option should only be used for debugging.
.br
If a new database is created,
.I hash
is used as hash key, instead of a random hash.
.SS Search options
.TP
.B -a, --augment
......
......@@ -491,6 +491,8 @@ int main (int argc, char **argv)/*{{{*/
int do_forced_unlock = 0;
int do_fast_index = 0;
unsigned int forced_hash_key = CREATE_RANDOM_DATABASE_HASH;
struct globber_array *omit_globs;
int result;
......@@ -537,6 +539,17 @@ int main (int argc, char **argv)/*{{{*/
} else if (!strcmp(*argv, "-F") ||
!strcmp(*argv, "--fast-index")) {
do_fast_index = 1;
} else if (!strcmp(*argv, "--force-hash-key-new-database")) {
++argv, --argc;
if (!argc) {
fprintf(stderr, "No hash key given after --force-hash-key-new-database\n");
exit(1);
}
if ( 1 != sscanf(*argv, "%u", &forced_hash_key) )
{
fprintf(stderr, "Hash key given after --force-hash-key-new-database could not be parsed\n");
exit(1);
}
} else if (!strcmp(*argv, "-v") || !strcmp(*argv, "--verbose")) {
verbose = 1;
} else if (!strcmp(*argv, "-V") || !strcmp(*argv, "--version")) {
......@@ -727,7 +740,7 @@ int main (int argc, char **argv)/*{{{*/
if (verbose) printf("Loaded %d existing messages\n", db->n_msgs);
} else if (ftype == M_NONE) {
if (verbose) printf("Starting new database\n");
db = new_database();
db = new_database( forced_hash_key );
} else {
fprintf(stderr, "database path %s is not a file; you can't put the database there\n", database_path);
unlock_and_exit(2);
......
......@@ -345,7 +345,8 @@ void insert_index_on_encoding(struct matches *m, int idx);
void add_token2_in_file(int file_index, unsigned int hash_key, char *tok_text, struct toktable2 *table, int add_to_chain1);
/* In db.c */
struct database *new_database(void);
#define CREATE_RANDOM_DATABASE_HASH 0
struct database *new_database(unsigned int hash_key);
struct database *new_database_from_file(char *db_filename, int do_integrity_checks);
void free_database(struct database *db);
void maybe_grow_message_arrays(struct database *db);
......
......@@ -771,7 +771,7 @@ static void try_copy_to_path(struct read_db *db, int msg_index, char *target_pat
if (out) {
fprintf(out, "X-source-folder: %s\n",
db->data + db->mbox_paths_table[mbi]);
fwrite(start, sizeof(char), msg_len, out);
fwrite(start, sizeof(char), msg_len?msg_len-1:0, out);
fclose(out);
}
}
......
*.status
*.data
.split_mboxen_marker
messages/mbox_split
messages/mh/BigMessages/1
messages/mh/BigMessages/2
messages/mh/BigMessages/3
messages/mh/BigMessages/4
!Makefile
add_messages maildir animals
assert_dump animals-maildir
\ No newline at end of file
add_messages mbox animals
assert_dump animals-mbox
add_messages mh animals
assert_dump animals-mh
\ No newline at end of file
add_messages maildir animals
add_messages mh animals
add_messages mbox animals
assert_dump animals
add_messages maildir animals
add_messages mh animals
add_messages mbox animals
assert_dump animals
remove_messages maildir animals
assert_dump animals-removed-maildir
purge_database animals-removed-maildir-purged
add_messages maildir animals
add_messages mh animals
add_messages mbox animals
assert_dump animals
remove_messages mbox animals
assert_dump animals-removed-mbox
purge_database animals-removed-mbox-purged
add_messages maildir animals
add_messages mh animals
add_messages mbox animals
assert_dump animals
remove_messages mh animals
assert_dump animals-removed-mh
purge_database animals-removed-mh-purged
add_messages maildir animals
add_messages mh animals
add_messages mbox animals
assert_dump animals
conf_set_mformat maildir
## from all different kinds of sources
search_messages animals a:server
assert_match maildir animals/cur/1294156254.3884_1.spencer:2,RS
assert_match maildir animals/cur/1294156254.3884_3.spencer:2,S
assert_match maildir animals/new/1294156254.3884_5.spencer
assert_match mh animals/1
assert_match mh animals/2
assert_match mbox animals/part.0
assert_match mbox animals/part.1
assert_no_more_matches
## from all different kinds of sources only a part of a mbox
search_messages animals Elephant/Mouse
assert_match maildir animals/cur/1294156254.3884_1.spencer:2,RS
assert_match mh animals/1
assert_match mh animals/2
assert_match mbox animals/part.0
assert_no_more_matches
## match in only maildir
search_messages animals Caterpillar/Elevator
assert_match maildir animals/cur/1294156254.3884_3.spencer:2,S
assert_match maildir animals/new/1294156254.3884_5.spencer
assert_no_more_matches
## match in only mh
search_messages animals Tiger
assert_match mh animals/1
assert_match mh animals/2
assert_no_more_matches
## match in only mbox
search_messages animals Frog/Cat
assert_match mbox animals/part.0
assert_match mbox animals/part.1
assert_no_more_matches
## match in only part of mbox
search_messages animals Frog
assert_match mbox animals/part.1
assert_no_more_matches
add_messages maildir animals
add_messages mh animals
add_messages mbox animals
assert_dump animals
conf_set_mformat mbox
## from all different kinds of sources
search_messages animals a:server
assert_match maildir animals/cur/1294156254.3884_1.spencer:2,RS
assert_match maildir animals/cur/1294156254.3884_3.spencer:2,S
assert_match maildir animals/new/1294156254.3884_5.spencer
assert_match mh animals/1
assert_match mh animals/2
assert_match mbox animals/part.0
assert_match mbox animals/part.1
assert_no_more_matches
## from all different kinds of sources only a part of a mbox
search_messages animals Elephant/Mouse
assert_match maildir animals/cur/1294156254.3884_1.spencer:2,RS
assert_match mh animals/1
assert_match mh animals/2
assert_match mbox animals/part.0
assert_no_more_matches
## match in only maildir
search_messages animals Caterpillar/Elevator
assert_match maildir animals/cur/1294156254.3884_3.spencer:2,S
assert_match maildir animals/new/1294156254.3884_5.spencer
assert_no_more_matches
## match in only mh
search_messages animals Tiger
assert_match mh animals/1
assert_match mh animals/2
assert_no_more_matches
## match in only mbox
search_messages animals Frog/Cat
assert_match mbox animals/part.0
assert_match mbox animals/part.1
assert_no_more_matches
## match in only part of mbox
search_messages animals Frog
assert_match mbox animals/part.1
assert_no_more_matches
add_messages maildir animals
add_messages mh animals
add_messages mbox animals
assert_dump animals
conf_set_mformat mh
## from all different kinds of sources
search_messages animals a:server
assert_match maildir animals/cur/1294156254.3884_1.spencer:2,RS
assert_match maildir animals/cur/1294156254.3884_3.spencer:2,S
assert_match maildir animals/new/1294156254.3884_5.spencer
assert_match mh animals/1
assert_match mh animals/2
assert_match mbox animals/part.0
assert_match mbox animals/part.1
assert_no_more_matches
## from all different kinds of sources only a part of a mbox
search_messages animals Elephant/Mouse
assert_match maildir animals/cur/1294156254.3884_1.spencer:2,RS
assert_match mh animals/1
assert_match mh animals/2
assert_match mbox animals/part.0
assert_no_more_matches
## match in only maildir
search_messages animals Caterpillar/Elevator
assert_match maildir animals/cur/1294156254.3884_3.spencer:2,S
assert_match maildir animals/new/1294156254.3884_5.spencer
assert_no_more_matches
## match in only mh
search_messages animals Tiger
assert_match mh animals/1
assert_match mh animals/2
assert_no_more_matches
## match in only mbox
search_messages animals Frog/Cat
assert_match mbox animals/part.0
assert_match mbox animals/part.1
assert_no_more_matches
## match in only part of mbox
search_messages animals Frog
assert_match mbox animals/part.1
assert_no_more_matches
add_messages mh attachments
assert_dump attachments
search_messages attachments n:first
assert_no_more_matches
search_messages attachments n:first=
assert_match mh attachments/1
assert_match mh attachments/2
assert_no_more_matches
search_messages attachments n:second_file.txt
assert_match mh attachments/1
assert_no_more_matches
add_messages maildir animals
add_messages mh animals
add_messages mbox animals
add_messages mh AliceBobEve
assert_dump animals-and-AliceBobEve
search_messages animals-and-AliceBobEve Robert
assert_match mh AliceBobEve/1
assert_match mh AliceBobEve/4
assert_match mh AliceBobEve/6
assert_no_more_matches
search_messages animals-and-AliceBobEve b:Robert
assert_match mh AliceBobEve/4
assert_match mh AliceBobEve/6
assert_no_more_matches
add_messages mh AliceBobEve
assert_dump AliceBobEve
search_messages AliceBobEve c:nil
assert_no_more_matches
search_messages AliceBobEve c:naive@good.heart
assert_match mh AliceBobEve/3
assert_no_more_matches
add_messages mh AliceBobEve
assert_dump AliceBobEve
search_messages AliceBobEve d:20050101-20061102
assert_no_more_matches
search_messages AliceBobEve d:20100101-20120101
assert_match mh AliceBobEve/1 # i.e.:2010-12-30 17:57:41 +0100
assert_match mh AliceBobEve/2 # i.e.:2010-12-31 17:58:41 +0100
assert_match mh AliceBobEve/3 # i.e.:2011-01-01 17:59:41 +0100
assert_match mh AliceBobEve/4 # i.e.:2011-05-19 18:00:41 +0100
assert_match mh AliceBobEve/5 # i.e.:2011-10-02 18:01:41 +0100
assert_match mh AliceBobEve/6 # i.e.:2011-12-31 18:02:41 +0100
assert_no_more_matches
search_messages AliceBobEve d:20100101-20110101
assert_match mh AliceBobEve/1 # i.e.:2010-12-30 17:57:41 +0100
assert_match mh AliceBobEve/2 # i.e.:2010-12-31 17:58:41 +0100
assert_match mh AliceBobEve/3 # i.e.:2011-01-01 17:59:41 +0100
assert_no_more_matches
search_messages AliceBobEve d:20110101-20120101
assert_match mh AliceBobEve/4 # i.e.:2011-05-19 18:00:41 +0100
assert_match mh AliceBobEve/5 # i.e.:2011-10-02 18:01:41 +0100
assert_match mh AliceBobEve/6 # i.e.:2011-12-31 18:02:41 +0100
assert_no_more_matches
search_messages AliceBobEve d:20110320-20111111
assert_match mh AliceBobEve/4 # i.e.:2011-05-19 18:00:41 +0100
assert_match mh AliceBobEve/5 # i.e.:2011-10-02 18:01:41 +0100
assert_no_more_matches
search_messages AliceBobEve d:20120320-20121010
assert_no_more_matches
add_messages mh AliceBobEve
assert_dump AliceBobEve
search_messages AliceBobEve d:20050101-
assert_match mh AliceBobEve/1 # i.e.:2010-12-30 17:57:41 +0100
assert_match mh AliceBobEve/2 # i.e.:2010-12-31 17:58:41 +0100
assert_match mh AliceBobEve/3 # i.e.:2011-01-01 17:59:41 +0100
assert_match mh AliceBobEve/4 # i.e.:2011-05-19 18:00:41 +0100
assert_match mh AliceBobEve/5 # i.e.:2011-10-02 18:01:41 +0100
assert_match mh AliceBobEve/6 # i.e.:2011-12-31 18:02:41 +0100
assert_no_more_matches
search_messages AliceBobEve d:20101230-
assert_match mh AliceBobEve/2 # i.e.:2010-12-31 17:58:41 +0100
assert_match mh AliceBobEve/3 # i.e.:2011-01-01 17:59:41 +0100
assert_match mh AliceBobEve/4 # i.e.:2011-05-19 18:00:41 +0100
assert_match mh AliceBobEve/5 # i.e.:2011-10-02 18:01:41 +0100
assert_match mh AliceBobEve/6 # i.e.:2011-12-31 18:02:41 +0100
assert_no_more_matches
search_messages AliceBobEve d:20110101-
assert_match mh AliceBobEve/4 # i.e.:2011-05-19 18:00:41 +0100
assert_match mh AliceBobEve/5 # i.e.:2011-10-02 18:01:41 +0100
assert_match mh AliceBobEve/6 # i.e.:2011-12-31 18:02:41 +0100
assert_no_more_matches
search_messages AliceBobEve d:20110706-
assert_match mh AliceBobEve/5 # i.e.:2011-10-02 18:01:41 +0100
assert_match mh AliceBobEve/6 # i.e.:2011-12-31 18:02:41 +0100
assert_no_more_matches
search_messages AliceBobEve d:20120201-
assert_no_more_matches
add_messages mh AliceBobEve
assert_dump AliceBobEve
## Sweeping through by end date ####################
search_messages AliceBobEve d:-20100101
assert_no_more_matches
search_messages AliceBobEve d:-20101231
assert_match mh AliceBobEve/1 # i.e.:2010-12-30 17:57:41 +0100
assert_match mh AliceBobEve/2 # i.e.:2010-12-31 17:58:41 +0100
assert_no_more_matches
search_messages AliceBobEve d:-20110101
assert_match mh AliceBobEve/1 # i.e.:2010-12-30 17:57:41 +0100
assert_match mh AliceBobEve/2 # i.e.:2010-12-31 17:58:41 +0100
assert_match mh AliceBobEve/3 # i.e.:2011-01-01 17:59:41 +0100
assert_no_more_matches
search_messages AliceBobEve d:-20110401
assert_match mh AliceBobEve/1 # i.e.:2010-12-30 17:57:41 +0100
assert_match mh AliceBobEve/2 # i.e.:2010-12-31 17:58:41 +0100
assert_match mh AliceBobEve/3 # i.e.:2011-01-01 17:59:41 +0100
assert_no_more_matches
search_messages AliceBobEve d:-20121031
assert_match mh AliceBobEve/1 # i.e.:2010-12-30 17:57:41 +0100
assert_match mh AliceBobEve/2 # i.e.:2010-12-31 17:58:41 +0100
assert_match mh AliceBobEve/3 # i.e.:2011-01-01 17:59:41 +0100
assert_match mh AliceBobEve/4 # i.e.:2011-05-19 18:00:41 +0100
assert_match mh AliceBobEve/5 # i.e.:2011-10-02 18:01:41 +0100
assert_match mh AliceBobEve/6 # i.e.:2011-12-31 18:02:41 +0100
assert_no_more_matches
add_messages maildir animals
add_messages mh animals
add_messages mbox animals
assert_dump animals
search_messages animals Elephant
assert_match maildir animals/cur/1294156254.3884_1.spencer:2,RS
assert_match mh animals/1
assert_match mh animals/2
assert_no_more_matches
search_messages animals Tiger
assert_match mh animals/1
assert_match mh animals/2
assert_no_more_matches
search_messages animals Mouse
assert_match mh animals/2
assert_match mbox animals/part.0
assert_no_more_matches
search_messages animals Cat
assert_match mbox animals/part.0
assert_no_more_matches
search_messages animals Caterpillar
assert_match maildir animals/new/1294156254.3884_5.spencer
assert_no_more_matches
######################################
## Adding Alice, Bob, and Eve
add_messages mh AliceBobEve
assert_dump animals-and-AliceBobEve
## search for email address
search_messages animals-and-AliceBobEve eve@ils.lair
assert_match mh AliceBobEve/2
assert_match mh AliceBobEve/3
assert_match mh AliceBobEve/4
assert_match mh AliceBobEve/5
assert_no_more_matches
add_messages maildir flags
assert_dump flags
search_messages flags F:s
assert_match maildir flags/cur/1:2,FRS
assert_match maildir flags/cur/2:2,RS
assert_match maildir flags/cur/3:2,FS
assert_match maildir flags/cur/4:2,S
assert_no_more_matches
search_messages flags F:-s
assert_match maildir flags/cur/5:2,FR
assert_match maildir flags/new/6:2,R
assert_match maildir flags/new/7:2,F
assert_match maildir flags/cur/8:2,
assert_no_more_matches
search_messages flags F:f
assert_match maildir flags/cur/1:2,FRS
assert_match maildir flags/cur/3:2,FS
assert_match maildir flags/cur/5:2,FR
assert_match maildir flags/new/7:2,F
assert_no_more_matches
search_messages flags F:-f
assert_match maildir flags/cur/2:2,RS
assert_match maildir flags/cur/4:2,S
assert_match maildir flags/new/6:2,R
assert_match maildir flags/cur/8:2,
assert_no_more_matches
search_messages flags F:r
assert_match maildir flags/cur/1:2,FRS
assert_match maildir flags/cur/2:2,RS
assert_match maildir flags/cur/5:2,FR
assert_match maildir flags/new/6:2,R
assert_no_more_matches
search_messages flags F:-r
assert_match maildir flags/cur/3:2,FS
assert_match maildir flags/cur/4:2,S
assert_match maildir flags/new/7:2,F
assert_match maildir flags/cur/8:2,
assert_no_more_matches
search_messages flags F:r-f
assert_match maildir flags/cur/2:2,RS
assert_match maildir flags/new/6:2,R
assert_no_more_matches
search_messages flags F:sfr
assert_match maildir flags/cur/1:2,FRS
assert_no_more_matches
search_messages flags F:rsf
assert_match maildir flags/cur/1:2,FRS
assert_no_more_matches
add_messages mh AliceBobEve
assert_dump AliceBobEve
## Empty search
search_messages AliceBobEve f:nil
assert_no_more_matches
## substring search in From:
search_messages AliceBobEve f:ob=
assert_match mh AliceBobEve/1
assert_match mh AliceBobEve/3
assert_match mh AliceBobEve/5
assert_no_more_matches
## exact search in From:
search_messages AliceBobEve f:eve@ils.lair
assert_match mh AliceBobEve/2
assert_match mh AliceBobEve/4
assert_no_more_matches
add_messages mh AliceBobEve
assert_dump AliceBobEve
search_messages AliceBobEve m:third@message.center
assert_match mh AliceBobEve/3
assert_no_more_matches
search_messages AliceBobEve m:fifth@message.center
assert_match mh AliceBobEve/5
assert_no_more_matches
search_messages AliceBobEve m:third@message.center/fifth@message.center
# nor "or" part, when searching for messages
#assert_match mh AliceBobEve/3
#assert_match mh AliceBobEve/5
assert_no_more_matches