Re: [PATCH v4 03/16] make shared crypto code behave library-like
[notmuch-archives.git] / a9 / 7a0169abe5d63b39a3f8bfea1954bb8b653d2e
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 2EB4B429E3C\r
6         for <notmuch@notmuchmail.org>; Tue, 14 Aug 2012 02:03:00 -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 vWccwqQCVDDU for <notmuch@notmuchmail.org>;\r
16         Tue, 14 Aug 2012 02:02:58 -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 424A4431FC7\r
21         for <notmuch@notmuchmail.org>; Tue, 14 Aug 2012 02:02:58 -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 1T1D1d-00062T-Ol; Tue, 14 Aug 2012 06:02:57 -0300\r
25 Received: (nullmailer pid 5274 invoked by uid 1000);\r
26         Mon, 13 Aug 2012 20:14:06 -0000\r
27 From: David Bremner <bremner@debian.org>\r
28 To: notmuch@notmuchmail.org\r
29 Subject: [Patch v2 2/6] test/hex-xcode: new test binary\r
30 Date: Mon, 13 Aug 2012 22:13:47 +0200\r
31 Message-Id: <1344888831-4301-3-git-send-email-bremner@debian.org>\r
32 X-Mailer: git-send-email 1.7.10.4\r
33 In-Reply-To: <1344888831-4301-1-git-send-email-bremner@debian.org>\r
34 References: <1344888831-4301-1-git-send-email-bremner@debian.org>\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: Tue, 14 Aug 2012 09:03:00 -0000\r
49 \r
50 This program is used both as a test-bed/unit-tester for\r
51 ../util/hex-escape.c, and also as a utility in future tests of dump\r
52 and restore.\r
53 ---\r
54  test/.gitignore     |    1 +\r
55  test/Makefile.local |   10 ++++-\r
56  test/basic          |    2 +-\r
57  test/hex-xcode.c    |  103 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
58  4 files changed, 114 insertions(+), 2 deletions(-)\r
59  create mode 100644 test/hex-xcode.c\r
60 \r
61 diff --git a/test/.gitignore b/test/.gitignore\r
62 index e63c689..be7ab5e 100644\r
63 --- a/test/.gitignore\r
64 +++ b/test/.gitignore\r
65 @@ -3,4 +3,5 @@ corpus.mail\r
66  smtp-dummy\r
67  symbol-test\r
68  arg-test\r
69 +hex-xcode\r
70  tmp.*\r
71 diff --git a/test/Makefile.local b/test/Makefile.local\r
72 index c7f1435..ab13814 100644\r
73 --- a/test/Makefile.local\r
74 +++ b/test/Makefile.local\r
75 @@ -13,6 +13,9 @@ smtp_dummy_modules = $(smtp_dummy_srcs:.c=.o)\r
76  $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a\r
77         $(call quiet,CC) -I. $^ -o $@\r
78  \r
79 +$(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libutil.a\r
80 +       $(call quiet,CC) -I. $^ -o $@ -ltalloc\r
81 +\r
82  $(dir)/smtp-dummy: $(smtp_dummy_modules)\r
83         $(call quiet,CC) $^ -o $@\r
84  \r
85 @@ -21,7 +24,12 @@ $(dir)/symbol-test: $(dir)/symbol-test.o\r
86  \r
87  .PHONY: test check\r
88  \r
89 -test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test\r
90 +TEST_BINARIES=$(dir)/arg-test \\r
91 +             $(dir)/hex-xcode \\r
92 +             $(dir)/smtp-dummy \\r
93 +             $(dir)/symbol-test\r
94 +\r
95 +test-binaries: $(TEST_BINARIES)\r
96  \r
97  test:  all test-binaries\r
98         @${dir}/notmuch-test $(OPTIONS)\r
99 diff --git a/test/basic b/test/basic\r
100 index d6aed24..3eebb37 100755\r
101 --- a/test/basic\r
102 +++ b/test/basic\r
103 @@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'\r
104  eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test)\r
105  tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)\r
106  available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -executable -printf '%f\n' | \\r
107 -    sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test)$/d" | \\r
108 +    sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|hex-escape)$/d" | \\r
109      sort)\r
110  test_expect_equal "$tests_in_suite" "$available"\r
111  \r
112 diff --git a/test/hex-xcode.c b/test/hex-xcode.c\r
113 new file mode 100644\r
114 index 0000000..eec6541\r
115 --- /dev/null\r
116 +++ b/test/hex-xcode.c\r
117 @@ -0,0 +1,103 @@\r
118 +/* No, nothing to to with IDE from Apple Inc.\r
119 +   testbed for ../util/hex-escape.c.\r
120 +\r
121 +   usage:\r
122 +   hex-xcode [--direction=(encode|decode)] [--omit-newline] < file\r
123 +   hex-xcode [--direction=(encode|decode)] [--omit-newline] arg1 arg2 arg3 ...\r
124 +\r
125 + */\r
126 +\r
127 +#include "notmuch-client.h"\r
128 +#include "hex-escape.h"\r
129 +#include <assert.h>\r
130 +\r
131 +\r
132 +enum direction {\r
133 +    ENCODE,\r
134 +    DECODE\r
135 +};\r
136 +\r
137 +static int\r
138 +xcode (void *ctx, enum direction dir, char *in, char **buf_p, size_t *size_p)\r
139 +{\r
140 +    hex_status_t status;\r
141 +\r
142 +    if (dir == ENCODE)\r
143 +       status = hex_encode (ctx, in, buf_p, size_p);\r
144 +    else\r
145 +       status = hex_decode (ctx, in, buf_p, size_p);\r
146 +\r
147 +    if (status == HEX_SUCCESS)\r
148 +       fputs (*buf_p, stdout);\r
149 +\r
150 +    return status;\r
151 +}\r
152 +\r
153 +\r
154 +int\r
155 +main (int argc, char **argv)\r
156 +{\r
157 +\r
158 +\r
159 +    enum direction dir = DECODE;\r
160 +    int omit_newline = FALSE;\r
161 +\r
162 +    notmuch_opt_desc_t options[] = {\r
163 +       { NOTMUCH_OPT_KEYWORD, &dir, "direction", 'd',\r
164 +         (notmuch_keyword_t []){ { "encode", ENCODE },\r
165 +                                 { "decode", DECODE },\r
166 +                                 { 0, 0 } } },\r
167 +       { NOTMUCH_OPT_BOOLEAN, &omit_newline, "omit-newline", 'n', 0 },\r
168 +       { 0, 0, 0, 0, 0 }\r
169 +    };\r
170 +\r
171 +    int opt_index = parse_arguments (argc, argv, options, 1);\r
172 +\r
173 +    if (opt_index < 0)\r
174 +       exit (1);\r
175 +\r
176 +    void *ctx = talloc_new (NULL);\r
177 +\r
178 +    char *line = NULL;\r
179 +    size_t line_size;\r
180 +    ssize_t line_len;\r
181 +\r
182 +    char *buffer = NULL;\r
183 +    size_t buf_size = 0;\r
184 +\r
185 +    notmuch_bool_t read_stdin = TRUE;\r
186 +\r
187 +    for (; opt_index < argc; opt_index++) {\r
188 +\r
189 +       if (xcode (ctx, dir, argv[opt_index],\r
190 +                  &buffer, &buf_size) != HEX_SUCCESS)\r
191 +           return 1;\r
192 +\r
193 +       if (!omit_newline)\r
194 +           putchar ('\n');\r
195 +\r
196 +       read_stdin = FALSE;\r
197 +    }\r
198 +\r
199 +    if (!read_stdin)\r
200 +       return 0;\r
201 +\r
202 +    while ((line_len = getline (&line, &line_size, stdin)) != -1) {\r
203 +\r
204 +       chomp_newline (line);\r
205 +\r
206 +       if (xcode (ctx, dir, line, &buffer, &buf_size) != HEX_SUCCESS)\r
207 +           return 1;\r
208 +\r
209 +       if (!omit_newline)\r
210 +           putchar ('\n');\r
211 +\r
212 +    }\r
213 +\r
214 +    if (line)\r
215 +       free (line);\r
216 +\r
217 +    talloc_free (ctx);\r
218 +\r
219 +    return 0;\r
220 +}\r
221 -- \r
222 1.7.10.4\r
223 \r