--- /dev/null
+Return-Path: <jani@nikula.org>\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 64FA0431FAF\r
+ for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 15:18:48 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 AA+Ibs8Khwqb for <notmuch@notmuchmail.org>;\r
+ Fri, 30 Nov 2012 15:18:43 -0800 (PST)\r
+Received: from mail-la0-f53.google.com (mail-la0-f53.google.com\r
+ [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 2441F431FAE\r
+ for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 15:18:42 -0800 (PST)\r
+Received: by mail-la0-f53.google.com with SMTP id w12so844899lag.26\r
+ for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 15:18:41 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=google.com; s=20120113;\r
+ h=from:to:cc:subject:in-reply-to:references:user-agent:date\r
+ :message-id:mime-version:content-type:x-gm-message-state;\r
+ bh=vOg/oRAlXQv5gUTgVuRwW62CCurn0BQjyOl3DFPZsQ8=;\r
+ b=F6gkjMxgZt0IgETVSkRc8tpCU2QMbsyXMBGsta/NUvtRo+vu1XLj0GnYywSb3MzSaM\r
+ ZDObYJNAh/0XxnpuUrFnDsu93BfjNI4gKcxoZlPNoUZF/FESnkiDqj3P8lI0pb54BE04\r
+ qXK0tP6V4jI1nGyeo0KBojLkuFShXRew5/p+3Kluf5rv7SVjX5ZeY0vB2ibT5bjRTa8Z\r
+ ynBuXFO9US4eTVl3xsnZRAFMr/07Bs5bpdBYZ7OAux1k0G9sAoqSm/VO/NOTwBYREBni\r
+ xR8DQMt6LGusbAoiHP4nyJPU4eyy8Fpm2P2R+pdxAdxyQyOevnH8rL7sGbprM744TrE4\r
+ sV+A==\r
+Received: by 10.112.38.226 with SMTP id j2mr1469259lbk.128.1354317521400;\r
+ Fri, 30 Nov 2012 15:18:41 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi.\r
+ [80.223.81.27])\r
+ by mx.google.com with ESMTPS id z9sm2576085lby.8.2012.11.30.15.18.39\r
+ (version=SSLv3 cipher=OTHER); Fri, 30 Nov 2012 15:18:40 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: david@tethera.net, notmuch@notmuchmail.org\r
+Subject: Re: [Patch v2 05/17] test: add generator for random "stub" messages\r
+In-Reply-To: <1353792017-31459-6-git-send-email-david@tethera.net>\r
+References: <1353792017-31459-1-git-send-email-david@tethera.net>\r
+ <1353792017-31459-6-git-send-email-david@tethera.net>\r
+User-Agent: Notmuch/0.14+124~g3b17402 (http://notmuchmail.org) Emacs/23.4.1\r
+ (i686-pc-linux-gnu)\r
+Date: Sat, 01 Dec 2012 01:18:37 +0200\r
+Message-ID: <87obieadde.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Gm-Message-State:\r
+ ALoCoQng7+yRm1TIse5GMilVCiCecZcs+pavU2I+I3CBB1ERl/m3DPvD5QvB0VWa//axoG2zKZ8I\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: Fri, 30 Nov 2012 23:18:48 -0000\r
+\r
+On Sat, 24 Nov 2012, david@tethera.net wrote:\r
+> From: David Bremner <bremner@debian.org>\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
+> updated for id:m2wr04ocro.fsf@guru.guru-group.fi\r
+>\r
+> - talk about Unicode value rather some specific encoding\r
+> - call talloc_realloc less times\r
+> ---\r
+> test/.gitignore | 1 +\r
+> test/Makefile.local | 10 +++\r
+> test/basic | 1 +\r
+> test/random-corpus.c | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
+> 4 files changed, 216 insertions(+)\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 8479f91..6a9f15e 100644\r
+> --- a/test/Makefile.local\r
+> +++ b/test/Makefile.local\r
+> @@ -16,6 +16,14 @@ $(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
+> + parse-time-string/libparse-time-string.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
+> @@ -29,6 +37,7 @@ $(dir)/parse-time: $(dir)/parse-time.o parse-time-string/parse-time-string.o\r
+> \r
+> TEST_BINARIES=$(dir)/arg-test \\r
+> $(dir)/hex-xcode \\r
+> + $(dir)/random-corpus \\r
+> $(dir)/parse-time \\r
+> $(dir)/smtp-dummy \\r
+> $(dir)/symbol-test\r
+> @@ -46,5 +55,6 @@ CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \\r
+> $(dir)/arg-test $(dir)/arg-test.o \\r
+> $(dir)/hex-xcode $(dir)/hex-xcode.o \\r
+> $(dir)/database-test.o \\r
+> + $(dir)/random-corpus $(dir)/random-corpus.o \\r
+> $(dir)/parse-time $(dir)/parse-time.o \\r
+> $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.*\r
+> diff --git a/test/basic b/test/basic\r
+> index 2a571ac..f93469f 100755\r
+> --- a/test/basic\r
+> +++ b/test/basic\r
+> @@ -59,6 +59,7 @@ available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -perm +111 \\r
+> ! -name hex-xcode \\r
+> ! -name notmuch-test \\r
+> ! -name parse-time \\r
+> + ! -name random-corpus \\r
+> ! -name smtp-dummy \\r
+> ! -name symbol-test \\r
+> ! -name test-verbose \\r
+> diff --git a/test/random-corpus.c b/test/random-corpus.c\r
+> new file mode 100644\r
+> index 0000000..085bda0\r
+> --- /dev/null\r
+> +++ b/test/random-corpus.c\r
+> @@ -0,0 +1,204 @@\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 Unicode value defined. Note that most of these will\r
+> + * be printed as boxes in most fonts.\r
+> + */\r
+> +\r
+> +#define GLYPH_MAX 0x10FFFE\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
+\r
+I wonder if there should be even more emphasis on ascii and unicode code\r
+points up to U+07FF (which maps to two UTF-8 bytes).\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
+> + size_t offset = 0;\r
+> + size_t i;\r
+> +\r
+\r
+Irritating blank line. ;)\r
+\r
+> + gchar *buf = NULL;\r
+> + size_t buf_size = 0;\r
+\r
+You could do an initial talloc of the buf based on char_count,\r
+e.g. twice that.\r
+\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, one for luck */\r
+> + while (buf_size - offset < 8) {\r
+\r
+I'd probably write that (offset + 8 >= buf_size).\r
+\r
+> + buf_size = 2 * buf_size + 8;\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 (message_id_len < 1) {\r
+> + fprintf (stderr, "message id's must be least length 1\n");\r
+> + exit (1);\r
+> + }\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
+> + /* explicitly allow zero tags */\r
+> + int num_tags = random () % (max_tags + 1);\r
+> + /* message ids should be non-empty */\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
+We'll probably want messages completely without tags in the tests\r
+too. How about a parameter to define the random-corpus tag. Which can be\r
+left out too. And if it's present, another parameter to tell whether it\r
+should be added even if num_tags == 0.\r
+\r
+Do the tags always come out sorted from the library? I'm wondering if\r
+it's a good idea to always put random-corpus there first. If it matters,\r
+you could use random () % num_tags to decide the position in the tag\r
+list to put the random-corpus tag in.\r
+\r
+BR,\r
+Jani.\r
+\r
+\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
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r