summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorLibravatar Jonathan Nieder <jrnieder@gmail.com>2011-01-02 21:05:46 -0600
committerLibravatar Jonathan Nieder <jrnieder@gmail.com>2011-02-26 04:59:37 -0600
commite832f43c1d26bf70611d98b62d95870a99292add (patch)
tree1b24a34f03268e1061ce6ee9c679c05b9912724b /t
parentt0081 (line-buffer): add buffering tests (diff)
downloadtgif-e832f43c1d26bf70611d98b62d95870a99292add.tar.xz
vcs-svn: add binary-safe read function
buffer_read_string works well for non line-oriented input except for one problem: it does not tell the caller how many bytes were actually written. This means that unless one is very careful about checking for errors (and eof) the calling program cannot tell the difference between the string "foo" followed by an early end of file and the string "foo\0bar\0baz". So introduce a variant that reports the length, too, a thinner wrapper around strbuf_fread. Its result is written to a strbuf so the caller does not need to keep track of the number of bytes read. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Diffstat (limited to 't')
-rwxr-xr-xt/t0081-line-buffer.sh18
1 files changed, 18 insertions, 0 deletions
diff --git a/t/t0081-line-buffer.sh b/t/t0081-line-buffer.sh
index 33a728ed98..a8eeb20645 100755
--- a/t/t0081-line-buffer.sh
+++ b/t/t0081-line-buffer.sh
@@ -151,6 +151,15 @@ test_expect_success 'skip, copy null byte' '
test_cmp expect actual
'
+test_expect_success 'read null byte' '
+ echo ">QhelloQ" | q_to_nul >expect &&
+ q_to_nul <<-\EOF | test-line-buffer >actual &&
+ binary 8
+ QhelloQ
+ EOF
+ test_cmp expect actual
+'
+
test_expect_success 'long reads are truncated' '
echo foo >expect &&
test-line-buffer <<-\EOF >actual &&
@@ -171,4 +180,13 @@ test_expect_success 'long copies are truncated' '
test_cmp expect actual
'
+test_expect_success 'long binary reads are truncated' '
+ echo ">foo" >expect &&
+ test-line-buffer <<-\EOF >actual &&
+ binary 5
+ foo
+ EOF
+ test_cmp expect actual
+'
+
test_done