database error
[notmuch-archives.git] / 6c / 6d50e58109390d92c38d71588747f774b25096
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 F0A78431FC0\r
6         for <notmuch@notmuchmail.org>; Sun, 18 Nov 2012 11:05:25 -0800 (PST)\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 K795cMR+u3-1 for <notmuch@notmuchmail.org>;\r
16         Sun, 18 Nov 2012 11:05:23 -0800 (PST)\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 2BB3C431FC2\r
21         for <notmuch@notmuchmail.org>; Sun, 18 Nov 2012 11:05:18 -0800 (PST)\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 1TaABA-000281-S6; Sun, 18 Nov 2012 15:05:17 -0400\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)\r
29         (envelope-from <bremner@tethera.net>)\r
30         id 1TaAB5-0001IF-AC; Sun, 18 Nov 2012 15:05:11 -0400\r
31 From: david@tethera.net\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH 02/16] test/hex-xcode: new test binary\r
34 Date: Sun, 18 Nov 2012 15:04:44 -0400\r
35 Message-Id: <1353265498-3839-3-git-send-email-david@tethera.net>\r
36 X-Mailer: git-send-email 1.7.10.4\r
37 In-Reply-To: <1353265498-3839-1-git-send-email-david@tethera.net>\r
38 References: <1353265498-3839-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, 18 Nov 2012 19:05:27 -0000\r
54 \r
55 From: David Bremner <bremner@debian.org>\r
56 \r
57 This program is used both as a test-bed/unit-tester for\r
58 ../util/hex-escape.c, and also as a utility in future tests of dump\r
59 and restore.\r
60 ---\r
61  test/.gitignore     |    1 +\r
62  test/Makefile.local |   13 ++++++-\r
63  test/basic          |    1 +\r
64  test/hex-xcode.c    |  103 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
65  4 files changed, 116 insertions(+), 2 deletions(-)\r
66  create mode 100644 test/hex-xcode.c\r
67 \r
68 diff --git a/test/.gitignore b/test/.gitignore\r
69 index e63c689..be7ab5e 100644\r
70 --- a/test/.gitignore\r
71 +++ b/test/.gitignore\r
72 @@ -3,4 +3,5 @@ corpus.mail\r
73  smtp-dummy\r
74  symbol-test\r
75  arg-test\r
76 +hex-xcode\r
77  tmp.*\r
78 diff --git a/test/Makefile.local b/test/Makefile.local\r
79 index 9ae130a..8da4c56 100644\r
80 --- a/test/Makefile.local\r
81 +++ b/test/Makefile.local\r
82 @@ -13,6 +13,9 @@ smtp_dummy_modules = $(smtp_dummy_srcs:.c=.o)\r
83  $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a\r
84         $(call quiet,CC) -I. $^ -o $@\r
85  \r
86 +$(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libutil.a\r
87 +       $(call quiet,CC) -I. $^ -o $@ -ltalloc\r
88 +\r
89  $(dir)/smtp-dummy: $(smtp_dummy_modules)\r
90         $(call quiet,CC) $^ -o $@\r
91  \r
92 @@ -24,8 +27,13 @@ $(dir)/parse-time: $(dir)/parse-time.o parse-time-string/parse-time-string.o\r
93  \r
94  .PHONY: test check\r
95  \r
96 -test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test \\r
97 -       $(dir)/parse-time\r
98 +TEST_BINARIES=$(dir)/arg-test \\r
99 +             $(dir)/hex-xcode \\r
100 +             $(dir)/parse-time \\r
101 +             $(dir)/smtp-dummy \\r
102 +             $(dir)/symbol-test\r
103 +\r
104 +test-binaries: $(TEST_BINARIES)\r
105  \r
106  test:  all test-binaries\r
107         @${dir}/notmuch-test $(OPTIONS)\r
108 @@ -36,5 +44,6 @@ SRCS := $(SRCS) $(smtp_dummy_srcs)\r
109  CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \\r
110          $(dir)/symbol-test $(dir)/symbol-test.o \\r
111          $(dir)/arg-test $(dir)/arg-test.o \\r
112 +        $(dir)/hex-xcode $(dir)/hex-xcode.o \\r
113          $(dir)/parse-time $(dir)/parse-time.o \\r
114          $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.*\r
115 diff --git a/test/basic b/test/basic\r
116 index 1b842d2..2a571ac 100755\r
117 --- a/test/basic\r
118 +++ b/test/basic\r
119 @@ -56,6 +56,7 @@ tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)\r
120  available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -perm +111  \\r
121      ! -name aggregate-results.sh       \\r
122      ! -name arg-test                   \\r
123 +    ! -name hex-xcode                  \\r
124      ! -name notmuch-test               \\r
125      ! -name parse-time                 \\r
126      ! -name smtp-dummy                 \\r
127 diff --git a/test/hex-xcode.c b/test/hex-xcode.c\r
128 new file mode 100644\r
129 index 0000000..eec6541\r
130 --- /dev/null\r
131 +++ b/test/hex-xcode.c\r
132 @@ -0,0 +1,103 @@\r
133 +/* No, nothing to to with IDE from Apple Inc.\r
134 +   testbed for ../util/hex-escape.c.\r
135 +\r
136 +   usage:\r
137 +   hex-xcode [--direction=(encode|decode)] [--omit-newline] < file\r
138 +   hex-xcode [--direction=(encode|decode)] [--omit-newline] arg1 arg2 arg3 ...\r
139 +\r
140 + */\r
141 +\r
142 +#include "notmuch-client.h"\r
143 +#include "hex-escape.h"\r
144 +#include <assert.h>\r
145 +\r
146 +\r
147 +enum direction {\r
148 +    ENCODE,\r
149 +    DECODE\r
150 +};\r
151 +\r
152 +static int\r
153 +xcode (void *ctx, enum direction dir, char *in, char **buf_p, size_t *size_p)\r
154 +{\r
155 +    hex_status_t status;\r
156 +\r
157 +    if (dir == ENCODE)\r
158 +       status = hex_encode (ctx, in, buf_p, size_p);\r
159 +    else\r
160 +       status = hex_decode (ctx, in, buf_p, size_p);\r
161 +\r
162 +    if (status == HEX_SUCCESS)\r
163 +       fputs (*buf_p, stdout);\r
164 +\r
165 +    return status;\r
166 +}\r
167 +\r
168 +\r
169 +int\r
170 +main (int argc, char **argv)\r
171 +{\r
172 +\r
173 +\r
174 +    enum direction dir = DECODE;\r
175 +    int omit_newline = FALSE;\r
176 +\r
177 +    notmuch_opt_desc_t options[] = {\r
178 +       { NOTMUCH_OPT_KEYWORD, &dir, "direction", 'd',\r
179 +         (notmuch_keyword_t []){ { "encode", ENCODE },\r
180 +                                 { "decode", DECODE },\r
181 +                                 { 0, 0 } } },\r
182 +       { NOTMUCH_OPT_BOOLEAN, &omit_newline, "omit-newline", 'n', 0 },\r
183 +       { 0, 0, 0, 0, 0 }\r
184 +    };\r
185 +\r
186 +    int opt_index = parse_arguments (argc, argv, options, 1);\r
187 +\r
188 +    if (opt_index < 0)\r
189 +       exit (1);\r
190 +\r
191 +    void *ctx = talloc_new (NULL);\r
192 +\r
193 +    char *line = NULL;\r
194 +    size_t line_size;\r
195 +    ssize_t line_len;\r
196 +\r
197 +    char *buffer = NULL;\r
198 +    size_t buf_size = 0;\r
199 +\r
200 +    notmuch_bool_t read_stdin = TRUE;\r
201 +\r
202 +    for (; opt_index < argc; opt_index++) {\r
203 +\r
204 +       if (xcode (ctx, dir, argv[opt_index],\r
205 +                  &buffer, &buf_size) != HEX_SUCCESS)\r
206 +           return 1;\r
207 +\r
208 +       if (!omit_newline)\r
209 +           putchar ('\n');\r
210 +\r
211 +       read_stdin = FALSE;\r
212 +    }\r
213 +\r
214 +    if (!read_stdin)\r
215 +       return 0;\r
216 +\r
217 +    while ((line_len = getline (&line, &line_size, stdin)) != -1) {\r
218 +\r
219 +       chomp_newline (line);\r
220 +\r
221 +       if (xcode (ctx, dir, line, &buffer, &buf_size) != HEX_SUCCESS)\r
222 +           return 1;\r
223 +\r
224 +       if (!omit_newline)\r
225 +           putchar ('\n');\r
226 +\r
227 +    }\r
228 +\r
229 +    if (line)\r
230 +       free (line);\r
231 +\r
232 +    talloc_free (ctx);\r
233 +\r
234 +    return 0;\r
235 +}\r
236 -- \r
237 1.7.10.4\r
238 \r