unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Cc: David Bremner <bremner@debian.org>, pere@hungry.com
Subject: [Alpha PATCH 2/6] test: add test for hex_(encode|decode)
Date: Tue, 13 Dec 2011 16:27:51 -0400	[thread overview]
Message-ID: <1323808075-7417-3-git-send-email-david@tethera.net> (raw)
In-Reply-To: <1323808075-7417-1-git-send-email-david@tethera.net>

From: David Bremner <bremner@debian.org>

The test binary hex-xcode can also be used to check for memory leaks.
---
 test/.gitignore     |    1 +
 test/Makefile.local |    6 +++-
 test/basic          |    2 +-
 test/hex-escaping   |   20 +++++++++++++
 test/hex-xcode.c    |   76 +++++++++++++++++++++++++++++++++++++++++++++++++++
 test/notmuch-test   |    1 +
 6 files changed, 104 insertions(+), 2 deletions(-)
 create mode 100755 test/hex-escaping
 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 6cb6c82..d27826a 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-escaping b/test/hex-escaping
new file mode 100755
index 0000000..d0a993e
--- /dev/null
+++ b/test/hex-escaping
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+test_description="hex encoding and decoding"
+. ./test-lib.sh
+
+test_begin_subtest "round trip"
+find $TEST_DIRECTORY/corpus -type f -print | sort | xargs cat > EXPECTED
+$TEST_DIRECTORY/hex-xcode e < EXPECTED | $TEST_DIRECTORY/hex-xcode d > OUTPUT
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "punctuation"
+tag1='comic_swear=$&^%$^%\\//-+$^%$'
+tag_enc1=$($TEST_DIRECTORY/hex-xcode e "$tag1")
+test_expect_equal "$tag_enc1" "comic_swear=%24%26%5e%25%24%5e%25%5c%5c%2f%2f-+%24%5e%25%24"
+
+test_begin_subtest "round trip newlines"
+printf 'this\n tag\t has\n spaces\n' > EXPECTED.$test_count
+$TEST_DIRECTORY/hex-xcode e  < EXPECTED.$test_count |\
+	$TEST_DIRECTORY/hex-xcode d > OUTPUT.$test_count
+test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
+test_done
diff --git a/test/hex-xcode.c b/test/hex-xcode.c
new file mode 100644
index 0000000..fff3e01
--- /dev/null
+++ b/test/hex-xcode.c
@@ -0,0 +1,76 @@
+/* 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 <assert.h>
+
+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;
+}
diff --git a/test/notmuch-test b/test/notmuch-test
index ded79e8..af72c73 100755
--- a/test/notmuch-test
+++ b/test/notmuch-test
@@ -50,6 +50,7 @@ TESTS="
   python
   hooks
   argument-parsing
+  hex-escaping
 "
 TESTS=${NOTMUCH_TESTS:=$TESTS}
 
-- 
1.7.5.4

  parent reply	other threads:[~2011-12-13 20:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-13 20:27 New Dump/Restore Format David Bremner
2011-12-13 20:27 ` [Alpha PATCH 1/6] util/hex-escape.[ch]: encoding/decoding strings into restricted character set David Bremner
2011-12-13 20:27 ` David Bremner [this message]
2011-12-13 20:27 ` [Alpha PATCH 3/6] notmuch-dump: add --format=(notmuch|sup) David Bremner
2011-12-13 20:27 ` [Alpha PATCH 4/6] test: add test for dump --format=notmuch David Bremner
2011-12-13 20:27 ` [Alpha PATCH 5/6] notmuch-restore: add --format=notmuch support David Bremner
2011-12-13 20:27 ` [Alpha PATCH 6/6] test: second set of dump/restore --format=notmuch tests David Bremner
2011-12-14 20:14   ` [Alpha Patch 1/2] test: add (currently broken) test 8 bit characters hex-escape and dump-restore David Bremner
2011-12-14 20:14     ` [Alpha Patch 2/2] test: update dump-restore tests for 8 bit characters David Bremner
2011-12-14 20:36       ` Dmitry Kurochkin
2011-12-14 23:20         ` David Bremner
2011-12-14 20:24   ` [Alpha PATCH 6/6] test: second set of dump/restore --format=notmuch tests Dmitry Kurochkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1323808075-7417-3-git-send-email-david@tethera.net \
    --to=david@tethera.net \
    --cc=bremner@debian.org \
    --cc=notmuch@notmuchmail.org \
    --cc=pere@hungry.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).