--- /dev/null
+Return-Path: <bremner@tesseract.cs.unb.ca>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id D8AD0429E32\r
+ for <notmuch@notmuchmail.org>; Tue, 14 Aug 2012 02:02:49 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id Xnc0DvKDj4a2 for <notmuch@notmuchmail.org>;\r
+ Tue, 14 Aug 2012 02:02:48 -0700 (PDT)\r
+Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])\r
+ (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 267BF431FB6\r
+ for <notmuch@notmuchmail.org>; Tue, 14 Aug 2012 02:02:48 -0700 (PDT)\r
+Received: from remotemail by tesseract.cs.unb.ca with local (Exim 4.72)\r
+ (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1T1D1T-000620-J5; Tue, 14 Aug 2012 06:02:47 -0300\r
+Received: (nullmailer pid 5280 invoked by uid 1000);\r
+ Mon, 13 Aug 2012 20:14:06 -0000\r
+From: David Bremner <bremner@debian.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [Patch v2 5/6] test: add generator for random "stub" messages\r
+Date: Mon, 13 Aug 2012 22:13:50 +0200\r
+Message-Id: <1344888831-4301-6-git-send-email-bremner@debian.org>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1344888831-4301-1-git-send-email-bremner@debian.org>\r
+References: <1344888831-4301-1-git-send-email-bremner@debian.org>\r
+Cc: David Bremner <bremner@debian.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 14 Aug 2012 09:02:50 -0000\r
+\r
+Initial use case is testing dump and restore, so we only have\r
+message-ids and tags.\r
+\r
+The message ID's are nothing like RFC compliant, but it doesn't seem\r
+any harder to roundtrip random UTF-8 strings than RFC-compliant ones.\r
+\r
+Tags are UTF-8, even though notmuch is in principle more generous than\r
+that.\r
+---\r
+ test/.gitignore | 1 +\r
+ test/Makefile.local | 8 ++\r
+ test/basic | 2 +-\r
+ test/random-corpus.c | 203 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 4 files changed, 213 insertions(+), 1 deletion(-)\r
+ create mode 100644 test/random-corpus.c\r
+\r
+diff --git a/test/.gitignore b/test/.gitignore\r
+index be7ab5e..1eff7ce 100644\r
+--- a/test/.gitignore\r
++++ b/test/.gitignore\r
+@@ -4,4 +4,5 @@ smtp-dummy\r
+ symbol-test\r
+ arg-test\r
+ hex-xcode\r
++random-corpus\r
+ tmp.*\r
+diff --git a/test/Makefile.local b/test/Makefile.local\r
+index ab13814..501aa4a 100644\r
+--- a/test/Makefile.local\r
++++ b/test/Makefile.local\r
+@@ -16,6 +16,13 @@ $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a\r
+ $(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libutil.a\r
+ $(call quiet,CC) -I. $^ -o $@ -ltalloc\r
+ \r
++random_corpus_deps = $(dir)/random-corpus.o $(dir)/database-test.o \\r
++ notmuch-config.o command-line-arguments.o \\r
++ lib/libnotmuch.a util/libutil.a\r
++\r
++$(dir)/random-corpus: $(random_corpus_deps)\r
++ $(call quiet,CC) $(CFLAGS_FINAL) $^ -o $@ $(CONFIGURE_LDFLAGS)\r
++\r
+ $(dir)/smtp-dummy: $(smtp_dummy_modules)\r
+ $(call quiet,CC) $^ -o $@\r
+ \r
+@@ -26,6 +33,7 @@ $(dir)/symbol-test: $(dir)/symbol-test.o\r
+ \r
+ TEST_BINARIES=$(dir)/arg-test \\r
+ $(dir)/hex-xcode \\r
++ $(dir)/random-corpus \\r
+ $(dir)/smtp-dummy \\r
+ $(dir)/symbol-test\r
+ \r
+diff --git a/test/basic b/test/basic\r
+index 3eebb37..d923d5a 100755\r
+--- a/test/basic\r
++++ b/test/basic\r
+@@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'\r
+ eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test)\r
+ tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)\r
+ available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -executable -printf '%f\n' | \\r
+- sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|hex-escape)$/d" | \\r
++ sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|hex-escape|random-corpus)$/d" | \\r
+ sort)\r
+ test_expect_equal "$tests_in_suite" "$available"\r
+ \r
+diff --git a/test/random-corpus.c b/test/random-corpus.c\r
+new file mode 100644\r
+index 0000000..a318267\r
+--- /dev/null\r
++++ b/test/random-corpus.c\r
+@@ -0,0 +1,203 @@\r
++/*\r
++ * Generate a random corpus of stub messages.\r
++ *\r
++ * Initial use case is testing dump and restore, so we only have\r
++ * message-ids and tags.\r
++ *\r
++ * Generated message-id's and tags are intentionally nasty.\r
++ *\r
++ * Copyright (c) 2012 David Bremner\r
++ *\r
++ * This program is free software: you can redistribute it and/or modify\r
++ * it under the terms of the GNU General Public License as published by\r
++ * the Free Software Foundation, either version 3 of the License, or\r
++ * (at your option) any later version.\r
++ *\r
++ * This program is distributed in the hope that it will be useful,\r
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
++ * GNU General Public License for more details.\r
++ *\r
++ * You should have received a copy of the GNU General Public License\r
++ * along with this program. If not, see http://www.gnu.org/licenses/ .\r
++ *\r
++ * Author: David Bremner <david@tethera.net>\r
++ */\r
++\r
++#include <stdlib.h>\r
++#include <assert.h>\r
++#include <talloc.h>\r
++#include <string.h>\r
++#include <glib.h>\r
++#include <math.h>\r
++\r
++#include "notmuch-client.h"\r
++#include "command-line-arguments.h"\r
++#include "database-test.h"\r
++\r
++/* Current largest UTF-32 value defined. Note that most of these will\r
++ * be printed as boxes in most fonts.\r
++ */\r
++\r
++#define GLYPH_MAX 0x10FFFE\r
++#define GLYPH_CLASSES 4\r
++\r
++static gunichar\r
++random_unichar ()\r
++{\r
++ int start=1, stop=GLYPH_MAX;\r
++ int class = random() % 2;\r
++\r
++ /*\r
++ * Choose about half ascii as test characters, as ascii\r
++ * punctation and whitespace is the main cause of problems for\r
++ * the (old) restore parser\r
++ */\r
++ switch (class) {\r
++ case 0:\r
++ /* ascii */\r
++ start=0x01;\r
++ stop=0x7f;\r
++ break;\r
++ case 1:\r
++ /* the rest of unicode */\r
++ start=0x80;\r
++ stop=GLYPH_MAX;\r
++ }\r
++\r
++ if (start == stop)\r
++ return start;\r
++ else\r
++ return start + (random() % (stop - start + 1));\r
++}\r
++\r
++static char *\r
++random_utf8_string (void *ctx, size_t char_count)\r
++{\r
++\r
++ gchar *buf = NULL;\r
++ size_t buf_size = 0;\r
++\r
++ size_t offset = 0;\r
++\r
++ size_t i;\r
++\r
++ buf = talloc_realloc (ctx, NULL, gchar, char_count);\r
++ buf_size = char_count;\r
++\r
++ for (i = 0; i < char_count; i++) {\r
++ gunichar randomchar;\r
++ size_t written;\r
++\r
++ /* 6 for one glyph, one for null */\r
++ if (buf_size - offset < 8) {\r
++ buf_size += 16;\r
++ buf = talloc_realloc (ctx, buf, gchar, buf_size);\r
++ }\r
++\r
++ randomchar = random_unichar();\r
++\r
++ written = g_unichar_to_utf8 (randomchar, buf + offset);\r
++\r
++ if (written <= 0) {\r
++ fprintf (stderr, "error converting to utf8\n");\r
++ exit (1);\r
++ }\r
++\r
++ offset += written;\r
++\r
++ }\r
++ buf[offset] = 0;\r
++ return buf;\r
++}\r
++\r
++\r
++int\r
++main (int argc, char **argv)\r
++{\r
++\r
++ void *ctx = talloc_new (NULL);\r
++\r
++ char *config_path = NULL;\r
++ notmuch_config_t *config;\r
++ notmuch_database_t *notmuch;\r
++\r
++ int num_messages = 500;\r
++ int max_tags = 10;\r
++ // leave room for UTF-8 encoding.\r
++ int tag_len = NOTMUCH_TAG_MAX / 6;\r
++ // NOTMUCH_MESSAGE_ID_MAX is not exported, so we make a\r
++ // conservative guess.\r
++ int message_id_len = (NOTMUCH_TAG_MAX - 20) / 6;\r
++\r
++ int seed = 734569;\r
++\r
++ notmuch_opt_desc_t options[] = {\r
++ { NOTMUCH_OPT_STRING, &config_path, "config-path", 'c', 0 },\r
++ { NOTMUCH_OPT_INT, &num_messages, "num-messages", 'n', 0 },\r
++ { NOTMUCH_OPT_INT, &max_tags, "max-tags", 'm', 0 },\r
++ { NOTMUCH_OPT_INT, &message_id_len, "message-id-len", 'M', 0 },\r
++ { NOTMUCH_OPT_INT, &tag_len, "tag-len", 't', 0 },\r
++ { NOTMUCH_OPT_INT, &seed, "seed", 's', 0 },\r
++ { 0, 0, 0, 0, 0 }\r
++ };\r
++\r
++ int opt_index = parse_arguments (argc, argv, options, 1);\r
++\r
++ if (opt_index < 0)\r
++ exit (1);\r
++\r
++ if (config_path == NULL) {\r
++ fprintf (stderr, "configuration path must be specified");\r
++ exit (1);\r
++ }\r
++\r
++ config = notmuch_config_open (ctx, config_path, NULL);\r
++ if (config == NULL)\r
++ return 1;\r
++\r
++ if (notmuch_database_open (notmuch_config_get_database_path (config),\r
++ NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))\r
++ return 1;\r
++\r
++ srandom (seed);\r
++\r
++ int count;\r
++ for (count = 0; count < num_messages; count++) {\r
++ int j;\r
++ int num_tags = random () % (max_tags + 1);\r
++ int this_mid_len = random () % message_id_len + 1;\r
++ const char **tag_list;\r
++ char *mid;\r
++ notmuch_status_t status;\r
++\r
++ do {\r
++ mid = random_utf8_string (ctx, this_mid_len);\r
++\r
++ tag_list = talloc_realloc (ctx, NULL, const char *, num_tags + 2);\r
++\r
++ tag_list[0] = "random-corpus";\r
++\r
++ for (j = 0; j < num_tags; j++) {\r
++ int this_tag_len = random () % tag_len + 1;\r
++\r
++ tag_list[j + 1] = random_utf8_string (ctx, this_tag_len);\r
++ }\r
++\r
++ tag_list[j + 1] = NULL;\r
++\r
++ status = notmuch_database_add_stub_message (notmuch, mid, tag_list);\r
++ } while (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID);\r
++\r
++ if (status != NOTMUCH_STATUS_SUCCESS) {\r
++ fprintf (stderr, "error %d adding message", status);\r
++ exit (status);\r
++ }\r
++ }\r
++\r
++ notmuch_database_destroy (notmuch);\r
++\r
++ talloc_free (ctx);\r
++\r
++ return 0;\r
++}\r
+-- \r
+1.7.10.4\r
+\r