Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 40 / d16e205f180296969162e0b39050ec85c7f6e8
1 Return-Path: <bremner@tesseract.cs.unb.ca>\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 53F50431FBD\r
6         for <notmuch@notmuchmail.org>; Mon, 20 Aug 2012 00:18:37 -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 f-gXYElhzCnR for <notmuch@notmuchmail.org>;\r
16         Mon, 20 Aug 2012 00:18:34 -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 2A8A3431FD2\r
21         for <notmuch@notmuchmail.org>; Mon, 20 Aug 2012 00:18:34 -0700 (PDT)\r
22 Received: from remotemail by tesseract.cs.unb.ca with local (Exim 4.72)\r
23         (envelope-from <bremner@tesseract.cs.unb.ca>)\r
24         id 1T3MFt-0002Fr-CZ; Mon, 20 Aug 2012 04:18:33 -0300\r
25 Received: (nullmailer pid 7812 invoked by uid 1000);\r
26         Sun, 19 Aug 2012 13:19:07 -0000\r
27 From: david@tethera.net\r
28 To: notmuch@notmuchmail.org\r
29 Subject: [Patch v3 2/6] test/hex-xcode: new test binary\r
30 Date: Sun, 19 Aug 2012 15:18:30 +0200\r
31 Message-Id: <1345382314-5330-3-git-send-email-david@tethera.net>\r
32 X-Mailer: git-send-email 1.7.10.4\r
33 In-Reply-To: <1345382314-5330-1-git-send-email-david@tethera.net>\r
34 References: <1345382314-5330-1-git-send-email-david@tethera.net>\r
35 Cc: David Bremner <bremner@debian.org>\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.13\r
38 Precedence: list\r
39 List-Id: "Use and development of the notmuch mail system."\r
40         <notmuch.notmuchmail.org>\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
42         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
44 List-Post: <mailto:notmuch@notmuchmail.org>\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
48 X-List-Received-Date: Mon, 20 Aug 2012 07:18:37 -0000\r
49 \r
50 From: David Bremner <bremner@debian.org>\r
51 \r
52 This program is used both as a test-bed/unit-tester for\r
53 ../util/hex-escape.c, and also as a utility in future tests of dump\r
54 and restore.\r
55 ---\r
56  test/.gitignore     |    1 +\r
57  test/Makefile.local |   11 +++++-\r
58  test/basic          |    2 +-\r
59  test/hex-xcode.c    |  103 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
60  4 files changed, 115 insertions(+), 2 deletions(-)\r
61  create mode 100644 test/hex-xcode.c\r
62 \r
63 diff --git a/test/.gitignore b/test/.gitignore\r
64 index e63c689..be7ab5e 100644\r
65 --- a/test/.gitignore\r
66 +++ b/test/.gitignore\r
67 @@ -3,4 +3,5 @@ corpus.mail\r
68  smtp-dummy\r
69  symbol-test\r
70  arg-test\r
71 +hex-xcode\r
72  tmp.*\r
73 diff --git a/test/Makefile.local b/test/Makefile.local\r
74 index c7f1435..2622185 100644\r
75 --- a/test/Makefile.local\r
76 +++ b/test/Makefile.local\r
77 @@ -13,6 +13,9 @@ smtp_dummy_modules = $(smtp_dummy_srcs:.c=.o)\r
78  $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a\r
79         $(call quiet,CC) -I. $^ -o $@\r
80  \r
81 +$(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libutil.a\r
82 +       $(call quiet,CC) -I. $^ -o $@ -ltalloc\r
83 +\r
84  $(dir)/smtp-dummy: $(smtp_dummy_modules)\r
85         $(call quiet,CC) $^ -o $@\r
86  \r
87 @@ -21,7 +24,12 @@ $(dir)/symbol-test: $(dir)/symbol-test.o\r
88  \r
89  .PHONY: test check\r
90  \r
91 -test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test\r
92 +TEST_BINARIES=$(dir)/arg-test \\r
93 +             $(dir)/hex-xcode \\r
94 +             $(dir)/smtp-dummy \\r
95 +             $(dir)/symbol-test\r
96 +\r
97 +test-binaries: $(TEST_BINARIES)\r
98  \r
99  test:  all test-binaries\r
100         @${dir}/notmuch-test $(OPTIONS)\r
101 @@ -32,4 +40,5 @@ SRCS := $(SRCS) $(smtp_dummy_srcs)\r
102  CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \\r
103          $(dir)/symbol-test $(dir)/symbol-test.o \\r
104          $(dir)/arg-test $(dir)/arg-test.o \\r
105 +        $(dir)/hex-xcode $(dir)/hex-xcode.o \\r
106          $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.*\r
107 diff --git a/test/basic b/test/basic\r
108 index d6aed24..af57026 100755\r
109 --- a/test/basic\r
110 +++ b/test/basic\r
111 @@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'\r
112  eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test)\r
113  tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)\r
114  available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -executable -printf '%f\n' | \\r
115 -    sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test)$/d" | \\r
116 +    sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|hex-xcode)$/d" | \\r
117      sort)\r
118  test_expect_equal "$tests_in_suite" "$available"\r
119  \r
120 diff --git a/test/hex-xcode.c b/test/hex-xcode.c\r
121 new file mode 100644\r
122 index 0000000..eec6541\r
123 --- /dev/null\r
124 +++ b/test/hex-xcode.c\r
125 @@ -0,0 +1,103 @@\r
126 +/* No, nothing to to with IDE from Apple Inc.\r
127 +   testbed for ../util/hex-escape.c.\r
128 +\r
129 +   usage:\r
130 +   hex-xcode [--direction=(encode|decode)] [--omit-newline] < file\r
131 +   hex-xcode [--direction=(encode|decode)] [--omit-newline] arg1 arg2 arg3 ...\r
132 +\r
133 + */\r
134 +\r
135 +#include "notmuch-client.h"\r
136 +#include "hex-escape.h"\r
137 +#include <assert.h>\r
138 +\r
139 +\r
140 +enum direction {\r
141 +    ENCODE,\r
142 +    DECODE\r
143 +};\r
144 +\r
145 +static int\r
146 +xcode (void *ctx, enum direction dir, char *in, char **buf_p, size_t *size_p)\r
147 +{\r
148 +    hex_status_t status;\r
149 +\r
150 +    if (dir == ENCODE)\r
151 +       status = hex_encode (ctx, in, buf_p, size_p);\r
152 +    else\r
153 +       status = hex_decode (ctx, in, buf_p, size_p);\r
154 +\r
155 +    if (status == HEX_SUCCESS)\r
156 +       fputs (*buf_p, stdout);\r
157 +\r
158 +    return status;\r
159 +}\r
160 +\r
161 +\r
162 +int\r
163 +main (int argc, char **argv)\r
164 +{\r
165 +\r
166 +\r
167 +    enum direction dir = DECODE;\r
168 +    int omit_newline = FALSE;\r
169 +\r
170 +    notmuch_opt_desc_t options[] = {\r
171 +       { NOTMUCH_OPT_KEYWORD, &dir, "direction", 'd',\r
172 +         (notmuch_keyword_t []){ { "encode", ENCODE },\r
173 +                                 { "decode", DECODE },\r
174 +                                 { 0, 0 } } },\r
175 +       { NOTMUCH_OPT_BOOLEAN, &omit_newline, "omit-newline", 'n', 0 },\r
176 +       { 0, 0, 0, 0, 0 }\r
177 +    };\r
178 +\r
179 +    int opt_index = parse_arguments (argc, argv, options, 1);\r
180 +\r
181 +    if (opt_index < 0)\r
182 +       exit (1);\r
183 +\r
184 +    void *ctx = talloc_new (NULL);\r
185 +\r
186 +    char *line = NULL;\r
187 +    size_t line_size;\r
188 +    ssize_t line_len;\r
189 +\r
190 +    char *buffer = NULL;\r
191 +    size_t buf_size = 0;\r
192 +\r
193 +    notmuch_bool_t read_stdin = TRUE;\r
194 +\r
195 +    for (; opt_index < argc; opt_index++) {\r
196 +\r
197 +       if (xcode (ctx, dir, argv[opt_index],\r
198 +                  &buffer, &buf_size) != HEX_SUCCESS)\r
199 +           return 1;\r
200 +\r
201 +       if (!omit_newline)\r
202 +           putchar ('\n');\r
203 +\r
204 +       read_stdin = FALSE;\r
205 +    }\r
206 +\r
207 +    if (!read_stdin)\r
208 +       return 0;\r
209 +\r
210 +    while ((line_len = getline (&line, &line_size, stdin)) != -1) {\r
211 +\r
212 +       chomp_newline (line);\r
213 +\r
214 +       if (xcode (ctx, dir, line, &buffer, &buf_size) != HEX_SUCCESS)\r
215 +           return 1;\r
216 +\r
217 +       if (!omit_newline)\r
218 +           putchar ('\n');\r
219 +\r
220 +    }\r
221 +\r
222 +    if (line)\r
223 +       free (line);\r
224 +\r
225 +    talloc_free (ctx);\r
226 +\r
227 +    return 0;\r
228 +}\r
229 -- \r
230 1.7.10.4\r
231 \r