Re: [Patch v2 02/17] test/hex-xcode: new test binary
authorJani Nikula <jani@nikula.org>
Fri, 30 Nov 2012 21:51:39 +0000 (23:51 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:51:14 +0000 (09:51 -0800)
b4/8445ef16b29c9ed4de39d98dbc6e580eaaad28 [new file with mode: 0644]

diff --git a/b4/8445ef16b29c9ed4de39d98dbc6e580eaaad28 b/b4/8445ef16b29c9ed4de39d98dbc6e580eaaad28
new file mode 100644 (file)
index 0000000..2157120
--- /dev/null
@@ -0,0 +1,272 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id B53F6431FAF\r
+       for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 13:51:49 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 3mqo3KSlCGQ6 for <notmuch@notmuchmail.org>;\r
+       Fri, 30 Nov 2012 13:51:44 -0800 (PST)\r
+Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com\r
+       [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 78D7F431FAE\r
+       for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 13:51:44 -0800 (PST)\r
+Received: by mail-lb0-f181.google.com with SMTP id ge1so916432lbb.26\r
+       for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 13:51:42 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=google.com; s=20120113;\r
+       h=from:to:cc:subject:in-reply-to:references:user-agent:date\r
+       :message-id:mime-version:content-type:x-gm-message-state;\r
+       bh=Yo7QO9QIIE+IY+Zi+Lo84vIkpBkjPVgJTzFkBRI8MpE=;\r
+       b=d3izCQfMA7wNAKxMVY4406T0wOhDpWqKFBvsOlSs+wmZ8b59l5SF94Q7vakCf6GCdl\r
+       9A2rXyp5zHvdms0elGLIHr8sT280J6wyNGjkzFot74nXZc85EKwfA+rjm4aZvctv17TT\r
+       vrQfjAry9HU50tpSpgjCmJ64Uq/y5SyPVAI+yO6MmwKBpanT24vDUbIvPI/wY+ShavyV\r
+       NlJggeG+9U41aC/BwnTj7voHyyOy2qZswwdYZNCGG47ojyIrfCxJuEjnU6jzIMk+SoDp\r
+       7wjMbtTyU23v3RD2zqk1F1fV5dLtvWrOh7FfLNhF9GRQQeQ+HfsOx5Mn9oMRIyYxJzte\r
+       C+wQ==\r
+Received: by 10.152.113.225 with SMTP id jb1mr2609763lab.23.1354312302746;\r
+       Fri, 30 Nov 2012 13:51:42 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi.\r
+       [80.223.81.27])\r
+       by mx.google.com with ESMTPS id p9sm2526297lbc.3.2012.11.30.13.51.40\r
+       (version=SSLv3 cipher=OTHER); Fri, 30 Nov 2012 13:51:41 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: david@tethera.net, notmuch@notmuchmail.org\r
+Subject: Re: [Patch v2 02/17] test/hex-xcode: new test binary\r
+In-Reply-To: <1353792017-31459-3-git-send-email-david@tethera.net>\r
+References: <1353792017-31459-1-git-send-email-david@tethera.net>\r
+       <1353792017-31459-3-git-send-email-david@tethera.net>\r
+User-Agent: Notmuch/0.14+124~g3b17402 (http://notmuchmail.org) Emacs/23.4.1\r
+       (i686-pc-linux-gnu)\r
+Date: Fri, 30 Nov 2012 23:51:39 +0200\r
+Message-ID: <87txs6iwt0.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Gm-Message-State:\r
+ ALoCoQkPmeUYKyCUSSduZDNOpdAssUTBfBmVutbzbGdqEoegc6iVeR24v1Yf3oiNkYxKivWnyScJ\r
+Cc: David Bremner <bremner@debian.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 30 Nov 2012 21:51:49 -0000\r
+\r
+On Sat, 24 Nov 2012, david@tethera.net wrote:\r
+> From: David Bremner <bremner@debian.org>\r
+>\r
+> This program is used both as a test-bed/unit-tester for\r
+> ../util/hex-escape.c, and also as a utility in future tests of dump\r
+> and restore.\r
+\r
+Should this have a mode for hex_decode_inplace()? It's silly from the\r
+tool perspective, but not from test coverage perspective.\r
+\r
+There'd be plenty to nitpick here, but it's only a test tool... so\r
+please just remove the extra/double newlines that seem to irritate me\r
+most. ;)\r
+\r
+Otherwise, looks good.\r
+\r
+BR,\r
+Jani.\r
+\r
+\r
+> ---\r
+>  test/.gitignore     |    1 +\r
+>  test/Makefile.local |   13 ++++++-\r
+>  test/basic          |    1 +\r
+>  test/hex-xcode.c    |  103 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
+>  4 files changed, 116 insertions(+), 2 deletions(-)\r
+>  create mode 100644 test/hex-xcode.c\r
+>\r
+> diff --git a/test/.gitignore b/test/.gitignore\r
+> index e63c689..be7ab5e 100644\r
+> --- a/test/.gitignore\r
+> +++ b/test/.gitignore\r
+> @@ -3,4 +3,5 @@ corpus.mail\r
+>  smtp-dummy\r
+>  symbol-test\r
+>  arg-test\r
+> +hex-xcode\r
+>  tmp.*\r
+> diff --git a/test/Makefile.local b/test/Makefile.local\r
+> index 9ae130a..8da4c56 100644\r
+> --- a/test/Makefile.local\r
+> +++ b/test/Makefile.local\r
+> @@ -13,6 +13,9 @@ smtp_dummy_modules = $(smtp_dummy_srcs:.c=.o)\r
+>  $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a\r
+>      $(call quiet,CC) -I. $^ -o $@\r
+>  \r
+> +$(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libutil.a\r
+> +    $(call quiet,CC) -I. $^ -o $@ -ltalloc\r
+> +\r
+>  $(dir)/smtp-dummy: $(smtp_dummy_modules)\r
+>      $(call quiet,CC) $^ -o $@\r
+>  \r
+> @@ -24,8 +27,13 @@ $(dir)/parse-time: $(dir)/parse-time.o parse-time-string/parse-time-string.o\r
+>  \r
+>  .PHONY: test check\r
+>  \r
+> -test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test \\r
+> -    $(dir)/parse-time\r
+> +TEST_BINARIES=$(dir)/arg-test \\r
+> +          $(dir)/hex-xcode \\r
+> +          $(dir)/parse-time \\r
+> +          $(dir)/smtp-dummy \\r
+> +          $(dir)/symbol-test\r
+> +\r
+> +test-binaries: $(TEST_BINARIES)\r
+>  \r
+>  test:       all test-binaries\r
+>      @${dir}/notmuch-test $(OPTIONS)\r
+> @@ -36,5 +44,6 @@ SRCS := $(SRCS) $(smtp_dummy_srcs)\r
+>  CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \\r
+>       $(dir)/symbol-test $(dir)/symbol-test.o \\r
+>       $(dir)/arg-test $(dir)/arg-test.o \\r
+> +     $(dir)/hex-xcode $(dir)/hex-xcode.o \\r
+>       $(dir)/parse-time $(dir)/parse-time.o \\r
+>       $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.*\r
+> diff --git a/test/basic b/test/basic\r
+> index 1b842d2..2a571ac 100755\r
+> --- a/test/basic\r
+> +++ b/test/basic\r
+> @@ -56,6 +56,7 @@ tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)\r
+>  available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -perm +111  \\r
+>      ! -name aggregate-results.sh    \\r
+>      ! -name arg-test                        \\r
+> +    ! -name hex-xcode                       \\r
+>      ! -name notmuch-test            \\r
+>      ! -name parse-time                      \\r
+>      ! -name smtp-dummy                      \\r
+> diff --git a/test/hex-xcode.c b/test/hex-xcode.c\r
+> new file mode 100644\r
+> index 0000000..eec6541\r
+> --- /dev/null\r
+> +++ b/test/hex-xcode.c\r
+> @@ -0,0 +1,103 @@\r
+> +/* No, nothing to to with IDE from Apple Inc.\r
+> +   testbed for ../util/hex-escape.c.\r
+> +\r
+> +   usage:\r
+> +   hex-xcode [--direction=(encode|decode)] [--omit-newline] < file\r
+> +   hex-xcode [--direction=(encode|decode)] [--omit-newline] arg1 arg2 arg3 ...\r
+> +\r
+> + */\r
+> +\r
+> +#include "notmuch-client.h"\r
+> +#include "hex-escape.h"\r
+> +#include <assert.h>\r
+> +\r
+> +\r
+> +enum direction {\r
+> +    ENCODE,\r
+> +    DECODE\r
+> +};\r
+> +\r
+> +static int\r
+> +xcode (void *ctx, enum direction dir, char *in, char **buf_p, size_t *size_p)\r
+> +{\r
+> +    hex_status_t status;\r
+> +\r
+> +    if (dir == ENCODE)\r
+> +    status = hex_encode (ctx, in, buf_p, size_p);\r
+> +    else\r
+> +    status = hex_decode (ctx, in, buf_p, size_p);\r
+> +\r
+> +    if (status == HEX_SUCCESS)\r
+> +    fputs (*buf_p, stdout);\r
+> +\r
+> +    return status;\r
+> +}\r
+> +\r
+> +\r
+> +int\r
+> +main (int argc, char **argv)\r
+> +{\r
+> +\r
+> +\r
+> +    enum direction dir = DECODE;\r
+> +    int omit_newline = FALSE;\r
+> +\r
+> +    notmuch_opt_desc_t options[] = {\r
+> +    { NOTMUCH_OPT_KEYWORD, &dir, "direction", 'd',\r
+> +      (notmuch_keyword_t []){ { "encode", ENCODE },\r
+> +                              { "decode", DECODE },\r
+> +                              { 0, 0 } } },\r
+> +    { NOTMUCH_OPT_BOOLEAN, &omit_newline, "omit-newline", 'n', 0 },\r
+> +    { 0, 0, 0, 0, 0 }\r
+> +    };\r
+> +\r
+> +    int opt_index = parse_arguments (argc, argv, options, 1);\r
+> +\r
+> +    if (opt_index < 0)\r
+> +    exit (1);\r
+> +\r
+> +    void *ctx = talloc_new (NULL);\r
+> +\r
+> +    char *line = NULL;\r
+> +    size_t line_size;\r
+> +    ssize_t line_len;\r
+> +\r
+> +    char *buffer = NULL;\r
+> +    size_t buf_size = 0;\r
+> +\r
+> +    notmuch_bool_t read_stdin = TRUE;\r
+> +\r
+> +    for (; opt_index < argc; opt_index++) {\r
+> +\r
+> +    if (xcode (ctx, dir, argv[opt_index],\r
+> +               &buffer, &buf_size) != HEX_SUCCESS)\r
+> +        return 1;\r
+> +\r
+> +    if (!omit_newline)\r
+> +        putchar ('\n');\r
+> +\r
+> +    read_stdin = FALSE;\r
+> +    }\r
+> +\r
+> +    if (!read_stdin)\r
+> +    return 0;\r
+> +\r
+> +    while ((line_len = getline (&line, &line_size, stdin)) != -1) {\r
+> +\r
+> +    chomp_newline (line);\r
+> +\r
+> +    if (xcode (ctx, dir, line, &buffer, &buf_size) != HEX_SUCCESS)\r
+> +        return 1;\r
+> +\r
+> +    if (!omit_newline)\r
+> +        putchar ('\n');\r
+> +\r
+> +    }\r
+> +\r
+> +    if (line)\r
+> +    free (line);\r
+> +\r
+> +    talloc_free (ctx);\r
+> +\r
+> +    return 0;\r
+> +}\r
+> -- \r
+> 1.7.10.4\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r