Re: [PATCH] lib: reword comment about XFOLDER: prefix
[notmuch-archives.git] / ec / 085d90d9ac7edaa194506586089bac4e91d8b0
1 Return-Path: <bremner@tethera.net>\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 4C983431FC7\r
6         for <notmuch@notmuchmail.org>; Sun,  5 Aug 2012 11:13:40 -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: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id QARCMulpjBKv for <notmuch@notmuchmail.org>;\r
16         Sun,  5 Aug 2012 11:13:38 -0700 (PDT)\r
17 Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])\r
18         (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id EB97B431FB6\r
21         for <notmuch@notmuchmail.org>; Sun,  5 Aug 2012 11:13:37 -0700 (PDT)\r
22 Received: from fctnnbsc30w-156034089108.dhcp-dynamic.fibreop.nb.bellaliant.net\r
23         ([156.34.89.108] helo=zancas.localnet)\r
24         by tesseract.cs.unb.ca with esmtpsa\r
25         (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)\r
26         (envelope-from <bremner@tethera.net>)\r
27         id 1Sy5KU-0006XL-Ud; Sun, 05 Aug 2012 15:13:35 -0300\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)\r
29         (envelope-from <bremner@tethera.net>)\r
30         id 1Sy5KP-0005x4-IH; Sun, 05 Aug 2012 15:13:25 -0300\r
31 From: david@tethera.net\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH 2/3] test: add generator for random "stub" messages\r
34 Date: Sun,  5 Aug 2012 15:13:12 -0300\r
35 Message-Id: <1344190393-22497-3-git-send-email-david@tethera.net>\r
36 X-Mailer: git-send-email 1.7.10.4\r
37 In-Reply-To: <1344190393-22497-1-git-send-email-david@tethera.net>\r
38 References: <1344190393-22497-1-git-send-email-david@tethera.net>\r
39 X-Spam_bar: -\r
40 Cc: David Bremner <bremner@debian.org>\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.13\r
43 Precedence: list\r
44 List-Id: "Use and development of the notmuch mail system."\r
45         <notmuch.notmuchmail.org>\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
49 List-Post: <mailto:notmuch@notmuchmail.org>\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
53 X-List-Received-Date: Sun, 05 Aug 2012 18:13:40 -0000\r
54 \r
55 From: David Bremner <bremner@debian.org>\r
56 \r
57 Initial use case is testing dump and restore, so we only have\r
58 message-ids and tags.\r
59 \r
60 The message ID's are nothing like RFC compliant, but it doesn't seem\r
61 any harder to roundtrip random UTF-8 strings than RFC-compliant ones.\r
62 \r
63 Tags are UTF-8, even though notmuch is in principle more generous than\r
64 that.\r
65 ---\r
66  test/.gitignore      |    1 +\r
67  test/Makefile.local  |   14 +++-\r
68  test/basic           |    2 +-\r
69  test/random-corpus.c |  201 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
70  4 files changed, 216 insertions(+), 2 deletions(-)\r
71  create mode 100644 test/random-corpus.c\r
72 \r
73 diff --git a/test/.gitignore b/test/.gitignore\r
74 index e63c689..e23017b 100644\r
75 --- a/test/.gitignore\r
76 +++ b/test/.gitignore\r
77 @@ -3,4 +3,5 @@ corpus.mail\r
78  smtp-dummy\r
79  symbol-test\r
80  arg-test\r
81 +random-corpus\r
82  tmp.*\r
83 diff --git a/test/Makefile.local b/test/Makefile.local\r
84 index c7f1435..586efc6 100644\r
85 --- a/test/Makefile.local\r
86 +++ b/test/Makefile.local\r
87 @@ -13,6 +13,13 @@ smtp_dummy_modules = $(smtp_dummy_srcs:.c=.o)\r
88  $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a\r
89         $(call quiet,CC) -I. $^ -o $@\r
90  \r
91 +random_corpus_deps =  $(dir)/random-corpus.o  $(dir)/database-test.o \\r
92 +                       notmuch-config.o command-line-arguments.o \\r
93 +                       lib/libnotmuch.a util/libutil.a\r
94 +\r
95 +$(dir)/random-corpus: $(random_corpus_deps)\r
96 +       $(call quiet,CC) $(CFLAGS_FINAL) $^ -o $@ $(CONFIGURE_LDFLAGS)\r
97 +\r
98  $(dir)/smtp-dummy: $(smtp_dummy_modules)\r
99         $(call quiet,CC) $^ -o $@\r
100  \r
101 @@ -21,7 +28,12 @@ $(dir)/symbol-test: $(dir)/symbol-test.o\r
102  \r
103  .PHONY: test check\r
104  \r
105 -test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test\r
106 +TEST_BINARIES=$(dir)/arg-test \\r
107 +             $(dir)/random-corpus \\r
108 +             $(dir)/smtp-dummy \\r
109 +             $(dir)/symbol-test\r
110 +\r
111 +test-binaries: $(TEST_BINARIES)\r
112  \r
113  test:  all test-binaries\r
114         @${dir}/notmuch-test $(OPTIONS)\r
115 diff --git a/test/basic b/test/basic\r
116 index d6aed24..589c4e2 100755\r
117 --- a/test/basic\r
118 +++ b/test/basic\r
119 @@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'\r
120  eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test)\r
121  tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)\r
122  available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -executable -printf '%f\n' | \\r
123 -    sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test)$/d" | \\r
124 +    sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|random-corpus)$/d" | \\r
125      sort)\r
126  test_expect_equal "$tests_in_suite" "$available"\r
127  \r
128 diff --git a/test/random-corpus.c b/test/random-corpus.c\r
129 new file mode 100644\r
130 index 0000000..ae900a6\r
131 --- /dev/null\r
132 +++ b/test/random-corpus.c\r
133 @@ -0,0 +1,201 @@\r
134 +/*\r
135 + * Generate a random corpus of stub messages.\r
136 + *\r
137 + * Initial use case is testing dump and restore, so we only have\r
138 + * message-ids and tags.\r
139 + *\r
140 + * Generated message-id's and tags are intentionally nasty.\r
141 + *\r
142 + * Copyright (c) 2012 David Bremner\r
143 + *\r
144 + * This program is free software: you can redistribute it and/or modify\r
145 + * it under the terms of the GNU General Public License as published by\r
146 + * the Free Software Foundation, either version 3 of the License, or\r
147 + * (at your option) any later version.\r
148 + *\r
149 + * This program is distributed in the hope that it will be useful,\r
150 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
151 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
152 + * GNU General Public License for more details.\r
153 + *\r
154 + * You should have received a copy of the GNU General Public License\r
155 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
156 + *\r
157 + * Author: David Bremner <david@tethera.net>\r
158 + */\r
159 +\r
160 +#include <stdlib.h>\r
161 +#include <assert.h>\r
162 +#include <talloc.h>\r
163 +#include <string.h>\r
164 +#include <glib.h>\r
165 +#include <math.h>\r
166 +\r
167 +#include "notmuch-client.h"\r
168 +#include "command-line-arguments.h"\r
169 +#include "database-test.h"\r
170 +\r
171 +/* Current largest UTF-32 value defined. Note that most of these will\r
172 + * be printed as boxes in most fonts.\r
173 + */\r
174 +\r
175 +#define GLYPH_MAX 0x10FFFE\r
176 +\r
177 +static gunichar\r
178 +random_unichar ()\r
179 +{\r
180 +    int start=1, stop=GLYPH_MAX;\r
181 +    int class = random() % 4;\r
182 +\r
183 +    switch (class) {\r
184 +    case 0:\r
185 +       /* control */\r
186 +       start=0x01;\r
187 +       stop=0x20;\r
188 +       break;\r
189 +    case 1:\r
190 +       start=0x21;\r
191 +       stop=0x7E;\r
192 +       break;\r
193 +    case 2:\r
194 +       start=0x41;\r
195 +       stop=0x7a;\r
196 +       break;\r
197 +    case 3:\r
198 +       start=0x7F;\r
199 +       stop=GLYPH_MAX;\r
200 +    }\r
201 +\r
202 +    return start + (random() % (start - stop + 1));\r
203 +}\r
204 +\r
205 +static char *\r
206 +random_utf8_string (void *ctx, size_t char_count)\r
207 +{\r
208 +\r
209 +    gchar *buf = NULL;\r
210 +    size_t buf_size = 0;\r
211 +\r
212 +    size_t offset = 0;\r
213 +\r
214 +    size_t i;\r
215 +\r
216 +    buf = talloc_realloc (ctx, NULL, gchar, char_count);\r
217 +    buf_size = char_count;\r
218 +\r
219 +    for (i = 0; i < char_count; i++) {\r
220 +       gunichar randomchar;\r
221 +       size_t written;\r
222 +\r
223 +       /* 6 for one glyph, one for null */\r
224 +       if (buf_size - offset < 8) {\r
225 +           buf_size += 16;\r
226 +           buf = talloc_realloc (ctx, buf, gchar, buf_size);\r
227 +       }\r
228 +\r
229 +       randomchar = random_unichar();\r
230 +\r
231 +       written = g_unichar_to_utf8 (randomchar, buf + offset);\r
232 +\r
233 +       if (written <= 0) {\r
234 +           fprintf (stderr, "error converting to utf8\n");\r
235 +           exit (1);\r
236 +       }\r
237 +\r
238 +       offset += written;\r
239 +\r
240 +    }\r
241 +    buf[offset] = 0;\r
242 +    return buf;\r
243 +}\r
244 +\r
245 +\r
246 +int\r
247 +main (int argc, char **argv)\r
248 +{\r
249 +\r
250 +    void *ctx = talloc_new (NULL);\r
251 +\r
252 +    char *config_path  = NULL;\r
253 +    notmuch_config_t *config;\r
254 +    notmuch_database_t *notmuch;\r
255 +\r
256 +    int num_messages = 500;\r
257 +    int max_tags = 10;\r
258 +    // leave room for UTF-8 encoding.\r
259 +    int tag_len = NOTMUCH_TAG_MAX / 6;\r
260 +    // NOTMUCH_MESSAGE_ID_MAX is not exported, so we make a\r
261 +    // conservative guess.\r
262 +    int message_id_len = (NOTMUCH_TAG_MAX - 20) / 6;\r
263 +\r
264 +    int seed = 734569;\r
265 +\r
266 +    notmuch_opt_desc_t options[] = {\r
267 +       { NOTMUCH_OPT_STRING, &config_path, "config-path", 'c', 0 },\r
268 +       { NOTMUCH_OPT_INT, &num_messages, "num-messages", 'n', 0 },\r
269 +       { NOTMUCH_OPT_INT, &max_tags, "max-tags", 'm', 0 },\r
270 +       { NOTMUCH_OPT_INT, &message_id_len, "message-id-len", 'M', 0 },\r
271 +       { NOTMUCH_OPT_INT, &tag_len, "tag-len", 't', 0 },\r
272 +       { NOTMUCH_OPT_INT, &seed, "seed", 's', 0 },\r
273 +       { 0, 0, 0, 0, 0 }\r
274 +    };\r
275 +\r
276 +    int opt_index = parse_arguments (argc, argv, options, 1);\r
277 +\r
278 +    if (opt_index < 0)\r
279 +       exit (1);\r
280 +\r
281 +    if (config_path == NULL) {\r
282 +       fprintf (stderr, "configuration path must be specified");\r
283 +       exit (1);\r
284 +    }\r
285 +\r
286 +    config = notmuch_config_open (ctx, config_path, NULL);\r
287 +    if (config == NULL)\r
288 +       return 1;\r
289 +\r
290 +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
291 +                              NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))\r
292 +       return 1;\r
293 +\r
294 +    srandom (seed);\r
295 +\r
296 +    int count;\r
297 +    for (count = 0; count < num_messages; count++) {\r
298 +       int j;\r
299 +       int num_tags = random () % (max_tags + 1);\r
300 +       int this_mid_len = random () % message_id_len + 1;\r
301 +       const char **tag_list;\r
302 +       char *mid;\r
303 +       notmuch_status_t status;\r
304 +\r
305 +       do {\r
306 +           mid = random_utf8_string (ctx, this_mid_len);\r
307 +\r
308 +           tag_list = talloc_realloc (ctx, NULL, const char *, num_tags + 2);\r
309 +\r
310 +           tag_list[0] = "random-corpus";\r
311 +\r
312 +           for (j = 0; j < num_tags; j++) {\r
313 +               int this_tag_len = random () % tag_len + 1;\r
314 +\r
315 +               tag_list[j + 1] = random_utf8_string (ctx, this_tag_len);\r
316 +           }\r
317 +\r
318 +           tag_list[j + 1] = NULL;\r
319 +\r
320 +           status = notmuch_database_add_stub_message (notmuch, mid, tag_list);\r
321 +       } while (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID);\r
322 +\r
323 +       if (status != NOTMUCH_STATUS_SUCCESS) {\r
324 +           fprintf (stderr, "error %d adding message", status);\r
325 +           exit (status);\r
326 +       }\r
327 +    }\r
328 +\r
329 +    notmuch_database_destroy (notmuch);\r
330 +\r
331 +    talloc_free (ctx);\r
332 +\r
333 +    return 0;\r
334 +}\r
335 -- \r
336 1.7.10.4\r
337 \r