From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 4831A429E31 for ; Sun, 18 Dec 2011 05:15:50 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.3 X-Spam-Level: X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_MED=-2.3] 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 Q--jq1hUts6w for ; Sun, 18 Dec 2011 05:15:48 -0800 (PST) Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 57442429E26 for ; Sun, 18 Dec 2011 05:15:43 -0800 (PST) Received: from zancas.localnet (fctnnbsc36w-156034079193.pppoe-dynamic.High-Speed.nb.bellaliant.net [156.34.79.193]) (authenticated bits=0) by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id pBIDFc0F017877 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Sun, 18 Dec 2011 09:15:39 -0400 Received: from bremner by zancas.localnet with local (Exim 4.77) (envelope-from ) id 1RcGaY-0008RG-Cd; Sun, 18 Dec 2011 09:15:38 -0400 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH Draft 2 2/9] test/hex-xcode: new test binary Date: Sun, 18 Dec 2011 09:15:04 -0400 Message-Id: <1324214111-32079-3-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1324214111-32079-1-git-send-email-david@tethera.net> References: <1324214111-32079-1-git-send-email-david@tethera.net> Cc: David Bremner 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: Sun, 18 Dec 2011 13: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 | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 85 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 fa2df73..ec507c4 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 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..20c1603 --- /dev/null +++ b/test/hex-xcode.c @@ -0,0 +1,78 @@ +/* No, nothing to to with IDE from Apple Inc. + testbed for ../util/hex-escape.c. + + usage: hex-xcode (e|d) < foo + + e is for encode + d is for decode + */ + +#include "notmuch-client.h" +#include "hex-escape.h" +#include + +static int +xcode (void *ctx, char dir, char *in, char **buf_p, size_t *size_p) +{ + hex_status_t status; + + if (dir == 'e') + status = hex_encode (ctx, in, buf_p, size_p); + else + status = hex_decode (ctx, in, buf_p, size_p); + + if (status == HEX_SUCCESS) + puts (*buf_p); + + return status; +} + + +int +main (int argc, char **argv) +{ + + assert (argc > 1 && argv[1]); + + char dir = argv[1][0]; + + void *ctx = talloc_new (NULL); + + char *line = NULL; + size_t line_size; + ssize_t line_len; + + char *buffer = NULL; + size_t buf_size = 0; + + int arg_index = 2; + notmuch_bool_t read_stdin = TRUE; + + for (arg_index = 2; arg_index < argc; arg_index++) { + + if (xcode (ctx, dir, argv[arg_index], + &buffer, &buf_size) != HEX_SUCCESS) + return 1; + + 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 (line) + free (line); + + talloc_free (ctx); + + return 0; +} -- 1.7.7.3