Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / c5 / 57cb9e316cb31ae977a62610d058e25fe7565a
1 Return-Path: <m.walters@qmul.ac.uk>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 2C119431FAF\r
6         for <notmuch@notmuchmail.org>; Wed,  8 Aug 2012 00:45:48 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.098\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
12         tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
13         NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id Je9eDjexR187 for <notmuch@notmuchmail.org>;\r
17         Wed,  8 Aug 2012 00:45:47 -0700 (PDT)\r
18 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id B1841431FAE\r
22         for <notmuch@notmuchmail.org>; Wed,  8 Aug 2012 00:45:46 -0700 (PDT)\r
23 Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
24         by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
25         (envelope-from <m.walters@qmul.ac.uk>)\r
26         id 1Sz0xc-0004fh-CK; Wed, 08 Aug 2012 08:45:44 +0100\r
27 Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
28         helo=localhost)\r
29         by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
30         (envelope-from <m.walters@qmul.ac.uk>)\r
31         id 1Sz0xb-000168-Mb; Wed, 08 Aug 2012 08:45:44 +0100\r
32 From: Mark Walters <markwalters1009@gmail.com>\r
33 To: david@tethera.net, notmuch@notmuchmail.org\r
34 Subject: Re: [PATCH 2/3] test: add generator for random "stub" messages\r
35 In-Reply-To: <1344190393-22497-3-git-send-email-david@tethera.net>\r
36 References: <1344190393-22497-1-git-send-email-david@tethera.net>\r
37         <1344190393-22497-3-git-send-email-david@tethera.net>\r
38 User-Agent: Notmuch/0.13.2+96~g634443c (http://notmuchmail.org) Emacs/23.4.1\r
39         (x86_64-pc-linux-gnu)\r
40 Date: Wed, 08 Aug 2012 08:45:38 +0100\r
41 Message-ID: <87393x3jz1.fsf@qmul.ac.uk>\r
42 MIME-Version: 1.0\r
43 Content-Type: text/plain; charset=us-ascii\r
44 X-Sender-Host-Address: 94.192.233.223\r
45 X-QM-SPAM-Info: Sender has good ham record.  :)\r
46 X-QM-Body-MD5: cf197f392d6b8db2e5d884d1ac31f9dd (of first 20000 bytes)\r
47 X-SpamAssassin-Score: -1.8\r
48 X-SpamAssassin-SpamBar: -\r
49 X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
50         determine if it is\r
51         spam. We require at least 5.0 points to mark a message as spam.\r
52         This message scored -1.8 points.\r
53         Summary of the scoring: \r
54         * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
55         *      medium trust\r
56         *      [138.37.6.40 listed in list.dnswl.org]\r
57         * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
58         provider *      (markwalters1009[at]gmail.com)\r
59         * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
60         *      domain\r
61         *  0.5 AWL AWL: From: address is in the auto white-list\r
62 X-QM-Scan-Virus: ClamAV says the message is clean\r
63 Cc: David Bremner <bremner@debian.org>\r
64 X-BeenThere: notmuch@notmuchmail.org\r
65 X-Mailman-Version: 2.1.13\r
66 Precedence: list\r
67 List-Id: "Use and development of the notmuch mail system."\r
68         <notmuch.notmuchmail.org>\r
69 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
71 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
72 List-Post: <mailto:notmuch@notmuchmail.org>\r
73 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
74 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
75         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
76 X-List-Received-Date: Wed, 08 Aug 2012 07:45:48 -0000\r
77 \r
78 \r
79 Hi I don't think I know enough Xapian to sensibly review the first patch\r
80 in this series.\r
81 \r
82 On Sun, 05 Aug 2012, david@tethera.net wrote:\r
83 > From: David Bremner <bremner@debian.org>\r
84 >\r
85 > Initial use case is testing dump and restore, so we only have\r
86 > message-ids and tags.\r
87 >\r
88 > The message ID's are nothing like RFC compliant, but it doesn't seem\r
89 > any harder to roundtrip random UTF-8 strings than RFC-compliant ones.\r
90 >\r
91 > Tags are UTF-8, even though notmuch is in principle more generous than\r
92 > that.\r
93 > ---\r
94 >  test/.gitignore      |    1 +\r
95 >  test/Makefile.local  |   14 +++-\r
96 >  test/basic           |    2 +-\r
97 >  test/random-corpus.c |  201 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
98 >  4 files changed, 216 insertions(+), 2 deletions(-)\r
99 >  create mode 100644 test/random-corpus.c\r
100 >\r
101 > diff --git a/test/.gitignore b/test/.gitignore\r
102 > index e63c689..e23017b 100644\r
103 > --- a/test/.gitignore\r
104 > +++ b/test/.gitignore\r
105 > @@ -3,4 +3,5 @@ corpus.mail\r
106 >  smtp-dummy\r
107 >  symbol-test\r
108 >  arg-test\r
109 > +random-corpus\r
110 >  tmp.*\r
111 > diff --git a/test/Makefile.local b/test/Makefile.local\r
112 > index c7f1435..586efc6 100644\r
113 > --- a/test/Makefile.local\r
114 > +++ b/test/Makefile.local\r
115 > @@ -13,6 +13,13 @@ smtp_dummy_modules = $(smtp_dummy_srcs:.c=.o)\r
116 >  $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a\r
117 >       $(call quiet,CC) -I. $^ -o $@\r
118 >  \r
119 > +random_corpus_deps =  $(dir)/random-corpus.o  $(dir)/database-test.o \\r
120 > +                     notmuch-config.o command-line-arguments.o \\r
121 > +                     lib/libnotmuch.a util/libutil.a\r
122 > +\r
123 > +$(dir)/random-corpus: $(random_corpus_deps)\r
124 > +     $(call quiet,CC) $(CFLAGS_FINAL) $^ -o $@ $(CONFIGURE_LDFLAGS)\r
125 > +\r
126 >  $(dir)/smtp-dummy: $(smtp_dummy_modules)\r
127 >       $(call quiet,CC) $^ -o $@\r
128 >  \r
129 > @@ -21,7 +28,12 @@ $(dir)/symbol-test: $(dir)/symbol-test.o\r
130 >  \r
131 >  .PHONY: test check\r
132 >  \r
133 > -test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test\r
134 > +TEST_BINARIES=$(dir)/arg-test \\r
135 > +           $(dir)/random-corpus \\r
136 > +           $(dir)/smtp-dummy \\r
137 > +           $(dir)/symbol-test\r
138 > +\r
139 > +test-binaries: $(TEST_BINARIES)\r
140 >  \r
141 >  test:        all test-binaries\r
142 >       @${dir}/notmuch-test $(OPTIONS)\r
143 > diff --git a/test/basic b/test/basic\r
144 > index d6aed24..589c4e2 100755\r
145 > --- a/test/basic\r
146 > +++ b/test/basic\r
147 > @@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'\r
148 >  eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test)\r
149 >  tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)\r
150 >  available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -executable -printf '%f\n' | \\r
151 > -    sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test)$/d" | \\r
152 > +    sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|random-corpus)$/d" | \\r
153 >      sort)\r
154 >  test_expect_equal "$tests_in_suite" "$available"\r
155 >  \r
156 > diff --git a/test/random-corpus.c b/test/random-corpus.c\r
157 > new file mode 100644\r
158 > index 0000000..ae900a6\r
159 > --- /dev/null\r
160 > +++ b/test/random-corpus.c\r
161 > @@ -0,0 +1,201 @@\r
162 > +/*\r
163 > + * Generate a random corpus of stub messages.\r
164 > + *\r
165 > + * Initial use case is testing dump and restore, so we only have\r
166 > + * message-ids and tags.\r
167 > + *\r
168 > + * Generated message-id's and tags are intentionally nasty.\r
169 > + *\r
170 > + * Copyright (c) 2012 David Bremner\r
171 > + *\r
172 > + * This program is free software: you can redistribute it and/or modify\r
173 > + * it under the terms of the GNU General Public License as published by\r
174 > + * the Free Software Foundation, either version 3 of the License, or\r
175 > + * (at your option) any later version.\r
176 > + *\r
177 > + * This program is distributed in the hope that it will be useful,\r
178 > + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
179 > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
180 > + * GNU General Public License for more details.\r
181 > + *\r
182 > + * You should have received a copy of the GNU General Public License\r
183 > + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
184 > + *\r
185 > + * Author: David Bremner <david@tethera.net>\r
186 > + */\r
187 > +\r
188 > +#include <stdlib.h>\r
189 > +#include <assert.h>\r
190 > +#include <talloc.h>\r
191 > +#include <string.h>\r
192 > +#include <glib.h>\r
193 > +#include <math.h>\r
194 > +\r
195 > +#include "notmuch-client.h"\r
196 > +#include "command-line-arguments.h"\r
197 > +#include "database-test.h"\r
198 > +\r
199 > +/* Current largest UTF-32 value defined. Note that most of these will\r
200 > + * be printed as boxes in most fonts.\r
201 > + */\r
202 > +\r
203 > +#define GLYPH_MAX 0x10FFFE\r
204 > +\r
205 > +static gunichar\r
206 > +random_unichar ()\r
207 > +{\r
208 > +    int start=1, stop=GLYPH_MAX;\r
209 > +    int class = random() % 4;\r
210 > +\r
211 > +    switch (class) {\r
212 > +    case 0:\r
213 > +     /* control */\r
214 > +     start=0x01;\r
215 > +     stop=0x20;\r
216 > +     break;\r
217 > +    case 1:\r
218 > +     start=0x21;\r
219 > +     stop=0x7E;\r
220 > +     break;\r
221 > +    case 2:\r
222 > +     start=0x41;\r
223 > +     stop=0x7a;\r
224 > +     break;\r
225 > +    case 3:\r
226 > +     start=0x7F;\r
227 > +     stop=GLYPH_MAX;\r
228 > +    }\r
229 \r
230 I think comments on other the classes might be helpful: I think Case 2\r
231 is Ascii A-z but that has a few characters between Z and a. Of course\r
232 since you are generating a random character it doesn't "matter".\r
233 \r
234 > +\r
235 > +    return start + (random() % (start - stop + 1));\r
236 > +}\r
237 \r
238 I think you mean % (stop - start + 1)?\r
239 \r
240 Otherwise this looks fine (I haven't actually run it yet).\r
241 \r
242 Best wishes\r
243 \r
244 Mark\r
245 \r
246 > +static char *\r
247 > +random_utf8_string (void *ctx, size_t char_count)\r
248 > +{\r
249 > +\r
250 > +    gchar *buf = NULL;\r
251 > +    size_t buf_size = 0;\r
252 > +\r
253 > +    size_t offset = 0;\r
254 > +\r
255 > +    size_t i;\r
256 > +\r
257 > +    buf = talloc_realloc (ctx, NULL, gchar, char_count);\r
258 > +    buf_size = char_count;\r
259 > +\r
260 > +    for (i = 0; i < char_count; i++) {\r
261 > +     gunichar randomchar;\r
262 > +     size_t written;\r
263 > +\r
264 > +     /* 6 for one glyph, one for null */\r
265 > +     if (buf_size - offset < 8) {\r
266 > +         buf_size += 16;\r
267 > +         buf = talloc_realloc (ctx, buf, gchar, buf_size);\r
268 > +     }\r
269 > +\r
270 > +     randomchar = random_unichar();\r
271 > +\r
272 > +     written = g_unichar_to_utf8 (randomchar, buf + offset);\r
273 > +\r
274 > +     if (written <= 0) {\r
275 > +         fprintf (stderr, "error converting to utf8\n");\r
276 > +         exit (1);\r
277 > +     }\r
278 > +\r
279 > +     offset += written;\r
280 > +\r
281 > +    }\r
282 > +    buf[offset] = 0;\r
283 > +    return buf;\r
284 > +}\r
285 > +\r
286 > +\r
287 > +int\r
288 > +main (int argc, char **argv)\r
289 > +{\r
290 > +\r
291 > +    void *ctx = talloc_new (NULL);\r
292 > +\r
293 > +    char *config_path  = NULL;\r
294 > +    notmuch_config_t *config;\r
295 > +    notmuch_database_t *notmuch;\r
296 > +\r
297 > +    int num_messages = 500;\r
298 > +    int max_tags = 10;\r
299 > +    // leave room for UTF-8 encoding.\r
300 > +    int tag_len = NOTMUCH_TAG_MAX / 6;\r
301 > +    // NOTMUCH_MESSAGE_ID_MAX is not exported, so we make a\r
302 > +    // conservative guess.\r
303 > +    int message_id_len = (NOTMUCH_TAG_MAX - 20) / 6;\r
304 > +\r
305 > +    int seed = 734569;\r
306 > +\r
307 > +    notmuch_opt_desc_t options[] = {\r
308 > +     { NOTMUCH_OPT_STRING, &config_path, "config-path", 'c', 0 },\r
309 > +     { NOTMUCH_OPT_INT, &num_messages, "num-messages", 'n', 0 },\r
310 > +     { NOTMUCH_OPT_INT, &max_tags, "max-tags", 'm', 0 },\r
311 > +     { NOTMUCH_OPT_INT, &message_id_len, "message-id-len", 'M', 0 },\r
312 > +     { NOTMUCH_OPT_INT, &tag_len, "tag-len", 't', 0 },\r
313 > +     { NOTMUCH_OPT_INT, &seed, "seed", 's', 0 },\r
314 > +     { 0, 0, 0, 0, 0 }\r
315 > +    };\r
316 > +\r
317 > +    int opt_index = parse_arguments (argc, argv, options, 1);\r
318 > +\r
319 > +    if (opt_index < 0)\r
320 > +     exit (1);\r
321 > +\r
322 > +    if (config_path == NULL) {\r
323 > +     fprintf (stderr, "configuration path must be specified");\r
324 > +     exit (1);\r
325 > +    }\r
326 > +\r
327 > +    config = notmuch_config_open (ctx, config_path, NULL);\r
328 > +    if (config == NULL)\r
329 > +     return 1;\r
330 > +\r
331 > +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
332 > +                            NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))\r
333 > +     return 1;\r
334 > +\r
335 > +    srandom (seed);\r
336 > +\r
337 > +    int count;\r
338 > +    for (count = 0; count < num_messages; count++) {\r
339 > +     int j;\r
340 > +     int num_tags = random () % (max_tags + 1);\r
341 > +     int this_mid_len = random () % message_id_len + 1;\r
342 > +     const char **tag_list;\r
343 > +     char *mid;\r
344 > +     notmuch_status_t status;\r
345 > +\r
346 > +     do {\r
347 > +         mid = random_utf8_string (ctx, this_mid_len);\r
348 > +\r
349 > +         tag_list = talloc_realloc (ctx, NULL, const char *, num_tags + 2);\r
350 > +\r
351 > +         tag_list[0] = "random-corpus";\r
352 > +\r
353 > +         for (j = 0; j < num_tags; j++) {\r
354 > +             int this_tag_len = random () % tag_len + 1;\r
355 > +\r
356 > +             tag_list[j + 1] = random_utf8_string (ctx, this_tag_len);\r
357 > +         }\r
358 > +\r
359 > +         tag_list[j + 1] = NULL;\r
360 > +\r
361 > +         status = notmuch_database_add_stub_message (notmuch, mid, tag_list);\r
362 > +     } while (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID);\r
363 > +\r
364 > +     if (status != NOTMUCH_STATUS_SUCCESS) {\r
365 > +         fprintf (stderr, "error %d adding message", status);\r
366 > +         exit (status);\r
367 > +     }\r
368 > +    }\r
369 > +\r
370 > +    notmuch_database_destroy (notmuch);\r
371 > +\r
372 > +    talloc_free (ctx);\r
373 > +\r
374 > +    return 0;\r
375 > +}\r
376 > -- \r
377 > 1.7.10.4\r
378 >\r
379 > _______________________________________________\r
380 > notmuch mailing list\r
381 > notmuch@notmuchmail.org\r
382 > http://notmuchmail.org/mailman/listinfo/notmuch\r