Re: [Patch v2 02/17] test/hex-xcode: new test binary
[notmuch-archives.git] / b4 / 8445ef16b29c9ed4de39d98dbc6e580eaaad28
1 Return-Path: <jani@nikula.org>\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 B53F6431FAF\r
6         for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 13:51:49 -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.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 3mqo3KSlCGQ6 for <notmuch@notmuchmail.org>;\r
16         Fri, 30 Nov 2012 13:51:44 -0800 (PST)\r
17 Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com\r
18         [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 78D7F431FAE\r
21         for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 13:51:44 -0800 (PST)\r
22 Received: by mail-lb0-f181.google.com with SMTP id ge1so916432lbb.26\r
23         for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 13:51:42 -0800 (PST)\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25         d=google.com; s=20120113;\r
26         h=from:to:cc:subject:in-reply-to:references:user-agent:date\r
27         :message-id:mime-version:content-type:x-gm-message-state;\r
28         bh=Yo7QO9QIIE+IY+Zi+Lo84vIkpBkjPVgJTzFkBRI8MpE=;\r
29         b=d3izCQfMA7wNAKxMVY4406T0wOhDpWqKFBvsOlSs+wmZ8b59l5SF94Q7vakCf6GCdl\r
30         9A2rXyp5zHvdms0elGLIHr8sT280J6wyNGjkzFot74nXZc85EKwfA+rjm4aZvctv17TT\r
31         vrQfjAry9HU50tpSpgjCmJ64Uq/y5SyPVAI+yO6MmwKBpanT24vDUbIvPI/wY+ShavyV\r
32         NlJggeG+9U41aC/BwnTj7voHyyOy2qZswwdYZNCGG47ojyIrfCxJuEjnU6jzIMk+SoDp\r
33         7wjMbtTyU23v3RD2zqk1F1fV5dLtvWrOh7FfLNhF9GRQQeQ+HfsOx5Mn9oMRIyYxJzte\r
34         C+wQ==\r
35 Received: by 10.152.113.225 with SMTP id jb1mr2609763lab.23.1354312302746;\r
36         Fri, 30 Nov 2012 13:51:42 -0800 (PST)\r
37 Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi.\r
38         [80.223.81.27])\r
39         by mx.google.com with ESMTPS id p9sm2526297lbc.3.2012.11.30.13.51.40\r
40         (version=SSLv3 cipher=OTHER); Fri, 30 Nov 2012 13:51:41 -0800 (PST)\r
41 From: Jani Nikula <jani@nikula.org>\r
42 To: david@tethera.net, notmuch@notmuchmail.org\r
43 Subject: Re: [Patch v2 02/17] test/hex-xcode: new test binary\r
44 In-Reply-To: <1353792017-31459-3-git-send-email-david@tethera.net>\r
45 References: <1353792017-31459-1-git-send-email-david@tethera.net>\r
46         <1353792017-31459-3-git-send-email-david@tethera.net>\r
47 User-Agent: Notmuch/0.14+124~g3b17402 (http://notmuchmail.org) Emacs/23.4.1\r
48         (i686-pc-linux-gnu)\r
49 Date: Fri, 30 Nov 2012 23:51:39 +0200\r
50 Message-ID: <87txs6iwt0.fsf@nikula.org>\r
51 MIME-Version: 1.0\r
52 Content-Type: text/plain; charset=us-ascii\r
53 X-Gm-Message-State:\r
54  ALoCoQkPmeUYKyCUSSduZDNOpdAssUTBfBmVutbzbGdqEoegc6iVeR24v1Yf3oiNkYxKivWnyScJ\r
55 Cc: David Bremner <bremner@debian.org>\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60         <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Fri, 30 Nov 2012 21:51:49 -0000\r
69 \r
70 On Sat, 24 Nov 2012, david@tethera.net wrote:\r
71 > From: David Bremner <bremner@debian.org>\r
72 >\r
73 > This program is used both as a test-bed/unit-tester for\r
74 > ../util/hex-escape.c, and also as a utility in future tests of dump\r
75 > and restore.\r
76 \r
77 Should this have a mode for hex_decode_inplace()? It's silly from the\r
78 tool perspective, but not from test coverage perspective.\r
79 \r
80 There'd be plenty to nitpick here, but it's only a test tool... so\r
81 please just remove the extra/double newlines that seem to irritate me\r
82 most. ;)\r
83 \r
84 Otherwise, looks good.\r
85 \r
86 BR,\r
87 Jani.\r
88 \r
89 \r
90 > ---\r
91 >  test/.gitignore     |    1 +\r
92 >  test/Makefile.local |   13 ++++++-\r
93 >  test/basic          |    1 +\r
94 >  test/hex-xcode.c    |  103 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
95 >  4 files changed, 116 insertions(+), 2 deletions(-)\r
96 >  create mode 100644 test/hex-xcode.c\r
97 >\r
98 > diff --git a/test/.gitignore b/test/.gitignore\r
99 > index e63c689..be7ab5e 100644\r
100 > --- a/test/.gitignore\r
101 > +++ b/test/.gitignore\r
102 > @@ -3,4 +3,5 @@ corpus.mail\r
103 >  smtp-dummy\r
104 >  symbol-test\r
105 >  arg-test\r
106 > +hex-xcode\r
107 >  tmp.*\r
108 > diff --git a/test/Makefile.local b/test/Makefile.local\r
109 > index 9ae130a..8da4c56 100644\r
110 > --- a/test/Makefile.local\r
111 > +++ b/test/Makefile.local\r
112 > @@ -13,6 +13,9 @@ smtp_dummy_modules = $(smtp_dummy_srcs:.c=.o)\r
113 >  $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a\r
114 >       $(call quiet,CC) -I. $^ -o $@\r
115 >  \r
116 > +$(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libutil.a\r
117 > +     $(call quiet,CC) -I. $^ -o $@ -ltalloc\r
118 > +\r
119 >  $(dir)/smtp-dummy: $(smtp_dummy_modules)\r
120 >       $(call quiet,CC) $^ -o $@\r
121 >  \r
122 > @@ -24,8 +27,13 @@ $(dir)/parse-time: $(dir)/parse-time.o parse-time-string/parse-time-string.o\r
123 >  \r
124 >  .PHONY: test check\r
125 >  \r
126 > -test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test \\r
127 > -     $(dir)/parse-time\r
128 > +TEST_BINARIES=$(dir)/arg-test \\r
129 > +           $(dir)/hex-xcode \\r
130 > +           $(dir)/parse-time \\r
131 > +           $(dir)/smtp-dummy \\r
132 > +           $(dir)/symbol-test\r
133 > +\r
134 > +test-binaries: $(TEST_BINARIES)\r
135 >  \r
136 >  test:        all test-binaries\r
137 >       @${dir}/notmuch-test $(OPTIONS)\r
138 > @@ -36,5 +44,6 @@ SRCS := $(SRCS) $(smtp_dummy_srcs)\r
139 >  CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \\r
140 >        $(dir)/symbol-test $(dir)/symbol-test.o \\r
141 >        $(dir)/arg-test $(dir)/arg-test.o \\r
142 > +      $(dir)/hex-xcode $(dir)/hex-xcode.o \\r
143 >        $(dir)/parse-time $(dir)/parse-time.o \\r
144 >        $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.*\r
145 > diff --git a/test/basic b/test/basic\r
146 > index 1b842d2..2a571ac 100755\r
147 > --- a/test/basic\r
148 > +++ b/test/basic\r
149 > @@ -56,6 +56,7 @@ tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)\r
150 >  available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -perm +111  \\r
151 >      ! -name aggregate-results.sh     \\r
152 >      ! -name arg-test                 \\r
153 > +    ! -name hex-xcode                        \\r
154 >      ! -name notmuch-test             \\r
155 >      ! -name parse-time                       \\r
156 >      ! -name smtp-dummy                       \\r
157 > diff --git a/test/hex-xcode.c b/test/hex-xcode.c\r
158 > new file mode 100644\r
159 > index 0000000..eec6541\r
160 > --- /dev/null\r
161 > +++ b/test/hex-xcode.c\r
162 > @@ -0,0 +1,103 @@\r
163 > +/* No, nothing to to with IDE from Apple Inc.\r
164 > +   testbed for ../util/hex-escape.c.\r
165 > +\r
166 > +   usage:\r
167 > +   hex-xcode [--direction=(encode|decode)] [--omit-newline] < file\r
168 > +   hex-xcode [--direction=(encode|decode)] [--omit-newline] arg1 arg2 arg3 ...\r
169 > +\r
170 > + */\r
171 > +\r
172 > +#include "notmuch-client.h"\r
173 > +#include "hex-escape.h"\r
174 > +#include <assert.h>\r
175 > +\r
176 > +\r
177 > +enum direction {\r
178 > +    ENCODE,\r
179 > +    DECODE\r
180 > +};\r
181 > +\r
182 > +static int\r
183 > +xcode (void *ctx, enum direction dir, char *in, char **buf_p, size_t *size_p)\r
184 > +{\r
185 > +    hex_status_t status;\r
186 > +\r
187 > +    if (dir == ENCODE)\r
188 > +     status = hex_encode (ctx, in, buf_p, size_p);\r
189 > +    else\r
190 > +     status = hex_decode (ctx, in, buf_p, size_p);\r
191 > +\r
192 > +    if (status == HEX_SUCCESS)\r
193 > +     fputs (*buf_p, stdout);\r
194 > +\r
195 > +    return status;\r
196 > +}\r
197 > +\r
198 > +\r
199 > +int\r
200 > +main (int argc, char **argv)\r
201 > +{\r
202 > +\r
203 > +\r
204 > +    enum direction dir = DECODE;\r
205 > +    int omit_newline = FALSE;\r
206 > +\r
207 > +    notmuch_opt_desc_t options[] = {\r
208 > +     { NOTMUCH_OPT_KEYWORD, &dir, "direction", 'd',\r
209 > +       (notmuch_keyword_t []){ { "encode", ENCODE },\r
210 > +                               { "decode", DECODE },\r
211 > +                               { 0, 0 } } },\r
212 > +     { NOTMUCH_OPT_BOOLEAN, &omit_newline, "omit-newline", 'n', 0 },\r
213 > +     { 0, 0, 0, 0, 0 }\r
214 > +    };\r
215 > +\r
216 > +    int opt_index = parse_arguments (argc, argv, options, 1);\r
217 > +\r
218 > +    if (opt_index < 0)\r
219 > +     exit (1);\r
220 > +\r
221 > +    void *ctx = talloc_new (NULL);\r
222 > +\r
223 > +    char *line = NULL;\r
224 > +    size_t line_size;\r
225 > +    ssize_t line_len;\r
226 > +\r
227 > +    char *buffer = NULL;\r
228 > +    size_t buf_size = 0;\r
229 > +\r
230 > +    notmuch_bool_t read_stdin = TRUE;\r
231 > +\r
232 > +    for (; opt_index < argc; opt_index++) {\r
233 > +\r
234 > +     if (xcode (ctx, dir, argv[opt_index],\r
235 > +                &buffer, &buf_size) != HEX_SUCCESS)\r
236 > +         return 1;\r
237 > +\r
238 > +     if (!omit_newline)\r
239 > +         putchar ('\n');\r
240 > +\r
241 > +     read_stdin = FALSE;\r
242 > +    }\r
243 > +\r
244 > +    if (!read_stdin)\r
245 > +     return 0;\r
246 > +\r
247 > +    while ((line_len = getline (&line, &line_size, stdin)) != -1) {\r
248 > +\r
249 > +     chomp_newline (line);\r
250 > +\r
251 > +     if (xcode (ctx, dir, line, &buffer, &buf_size) != HEX_SUCCESS)\r
252 > +         return 1;\r
253 > +\r
254 > +     if (!omit_newline)\r
255 > +         putchar ('\n');\r
256 > +\r
257 > +    }\r
258 > +\r
259 > +    if (line)\r
260 > +     free (line);\r
261 > +\r
262 > +    talloc_free (ctx);\r
263 > +\r
264 > +    return 0;\r
265 > +}\r
266 > -- \r
267 > 1.7.10.4\r
268 >\r
269 > _______________________________________________\r
270 > notmuch mailing list\r
271 > notmuch@notmuchmail.org\r
272 > http://notmuchmail.org/mailman/listinfo/notmuch\r