From e880d0c8bf42ff7763b65fb23914ca4276d6c213 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Sat, 14 Apr 2012 15:15:27 +0300 Subject: [PATCH] [PATCH v2 2/6] test/hex-xcode: new test binary --- 67/59835957c5c02370ddfe283bec9bd9f1e3e02e | 240 ++++++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 67/59835957c5c02370ddfe283bec9bd9f1e3e02e diff --git a/67/59835957c5c02370ddfe283bec9bd9f1e3e02e b/67/59835957c5c02370ddfe283bec9bd9f1e3e02e new file mode 100644 index 000000000..36a8580df --- /dev/null +++ b/67/59835957c5c02370ddfe283bec9bd9f1e3e02e @@ -0,0 +1,240 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 11FC6431FD4 + for ; Sat, 14 Apr 2012 05:15:50 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id PtgvYZdRCvnO for ; + Sat, 14 Apr 2012 05:15:47 -0700 (PDT) +Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com + [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id AD00D431FBD + for ; Sat, 14 Apr 2012 05:15:44 -0700 (PDT) +Received: by mail-lb0-f181.google.com with SMTP id b5so40243lbd.26 + for ; Sat, 14 Apr 2012 05:15:44 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=google.com; s=20120113; + h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references + :in-reply-to:references:x-gm-message-state; + bh=Sa1X0bPHRHQiErxc62pbcrRL7R+yylPzZFHAcy3qFDg=; + b=UQW/c/BT2H/4ZwbErZ1DnxE2z4eHKHI+xSfE7yjX7uR7cemkQYqeBFPf8/RI7vgmH3 + M9/wPtBKIRTVKHpC/oYS67MM9XY/YzoRAMZtObRzaFfHDXGDfJbgecCAnDp77Pi3H8fT + 6gZzJvktB3DDSo7lFaRuqJV09iUY6gaZfYH/Wpua8viDvzBXqFnMrq+9grOWhBFPNMHD + 9crvmyxMlYvcFTTAeDqzn8wNgyuRYfgmvcLnZ4W+JyEOGPKjVhR60OOUe2PffLIJ8m2R + reeC8nU7I5TfkYpKHN0JLvWT85lnIa84YVHsk3GjYFI2Ld3kIG0NGCKaB56aUXDxZShz + YiZw== +Received: by 10.112.37.134 with SMTP id y6mr2162112lbj.102.1334405744334; + Sat, 14 Apr 2012 05:15:44 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw4-fe50dc00-68.dhcp.inet.fi. + [80.220.80.68]) + by mx.google.com with ESMTPS id fe6sm16009481lbb.9.2012.04.14.05.15.42 + (version=SSLv3 cipher=OTHER); Sat, 14 Apr 2012 05:15:43 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH v2 2/6] test/hex-xcode: new test binary +Date: Sat, 14 Apr 2012 15:15:27 +0300 +Message-Id: + +X-Mailer: git-send-email 1.7.5.4 +In-Reply-To: +References: +In-Reply-To: +References: +X-Gm-Message-State: + ALoCoQmAJ8obfLHNsoFrwJw5pOpNhKThPzRJdHC4Cj28NqT9Xa1pxeEMnN7AAZ9yDS9scNWXWEeN +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 14 Apr 2012 12:15:50 -0000 + +From: David Bremner + +This program is used both as a test-bed/unit-tester for +../util/hex-escape.c, and also as a utility in future tests of dump +and restore. +--- + test/.gitignore | 1 + + test/Makefile.local | 6 ++- + test/basic | 2 +- + test/hex-xcode.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++ + 4 files changed, 110 insertions(+), 2 deletions(-) + create mode 100644 test/hex-xcode.c + +diff --git a/test/.gitignore b/test/.gitignore +index e63c689..be7ab5e 100644 +--- a/test/.gitignore ++++ b/test/.gitignore +@@ -3,4 +3,5 @@ corpus.mail + smtp-dummy + symbol-test + arg-test ++hex-xcode + tmp.* +diff --git a/test/Makefile.local b/test/Makefile.local +index 4a6a4b1..9cecd28 100644 +--- a/test/Makefile.local ++++ b/test/Makefile.local +@@ -13,6 +13,9 @@ smtp_dummy_modules = $(smtp_dummy_srcs:.c=.o) + $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a + $(call quiet,CC) -I. $^ -o $@ + ++$(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libutil.a ++ $(call quiet,CC) -I. $^ -o $@ -ltalloc ++ + $(dir)/smtp-dummy: $(smtp_dummy_modules) + $(call quiet,CC) $^ -o $@ + +@@ -21,7 +24,8 @@ $(dir)/symbol-test: $(dir)/symbol-test.o + + .PHONY: test check + +-test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test ++test-binaries: $(dir)/arg-test $(dir)/hex-xcode \ ++ $(dir)/smtp-dummy $(dir)/symbol-test + + test: all test-binaries + @${dir}/notmuch-test $(OPTIONS) +diff --git a/test/basic b/test/basic +index d6aed24..af57026 100755 +--- a/test/basic ++++ b/test/basic +@@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test' + eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test) + tests_in_suite=$(for i in $TESTS; do echo $i; done | sort) + available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -executable -printf '%f\n' | \ +- sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test)$/d" | \ ++ sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|hex-xcode)$/d" | \ + sort) + test_expect_equal "$tests_in_suite" "$available" + +diff --git a/test/hex-xcode.c b/test/hex-xcode.c +new file mode 100644 +index 0000000..eec6541 +--- /dev/null ++++ b/test/hex-xcode.c +@@ -0,0 +1,103 @@ ++/* No, nothing to to with IDE from Apple Inc. ++ testbed for ../util/hex-escape.c. ++ ++ usage: ++ hex-xcode [--direction=(encode|decode)] [--omit-newline] < file ++ hex-xcode [--direction=(encode|decode)] [--omit-newline] arg1 arg2 arg3 ... ++ ++ */ ++ ++#include "notmuch-client.h" ++#include "hex-escape.h" ++#include ++ ++ ++enum direction { ++ ENCODE, ++ DECODE ++}; ++ ++static int ++xcode (void *ctx, enum direction dir, char *in, char **buf_p, size_t *size_p) ++{ ++ hex_status_t status; ++ ++ if (dir == ENCODE) ++ status = hex_encode (ctx, in, buf_p, size_p); ++ else ++ status = hex_decode (ctx, in, buf_p, size_p); ++ ++ if (status == HEX_SUCCESS) ++ fputs (*buf_p, stdout); ++ ++ return status; ++} ++ ++ ++int ++main (int argc, char **argv) ++{ ++ ++ ++ enum direction dir = DECODE; ++ int omit_newline = FALSE; ++ ++ notmuch_opt_desc_t options[] = { ++ { NOTMUCH_OPT_KEYWORD, &dir, "direction", 'd', ++ (notmuch_keyword_t []){ { "encode", ENCODE }, ++ { "decode", DECODE }, ++ { 0, 0 } } }, ++ { NOTMUCH_OPT_BOOLEAN, &omit_newline, "omit-newline", 'n', 0 }, ++ { 0, 0, 0, 0, 0 } ++ }; ++ ++ int opt_index = parse_arguments (argc, argv, options, 1); ++ ++ if (opt_index < 0) ++ exit (1); ++ ++ void *ctx = talloc_new (NULL); ++ ++ char *line = NULL; ++ size_t line_size; ++ ssize_t line_len; ++ ++ char *buffer = NULL; ++ size_t buf_size = 0; ++ ++ notmuch_bool_t read_stdin = TRUE; ++ ++ for (; opt_index < argc; opt_index++) { ++ ++ if (xcode (ctx, dir, argv[opt_index], ++ &buffer, &buf_size) != HEX_SUCCESS) ++ return 1; ++ ++ if (!omit_newline) ++ putchar ('\n'); ++ ++ read_stdin = FALSE; ++ } ++ ++ if (!read_stdin) ++ return 0; ++ ++ while ((line_len = getline (&line, &line_size, stdin)) != -1) { ++ ++ chomp_newline (line); ++ ++ if (xcode (ctx, dir, line, &buffer, &buf_size) != HEX_SUCCESS) ++ return 1; ++ ++ if (!omit_newline) ++ putchar ('\n'); ++ ++ } ++ ++ if (line) ++ free (line); ++ ++ talloc_free (ctx); ++ ++ return 0; ++} +-- +1.7.5.4 + -- 2.26.2