summaryrefslogtreecommitdiff
path: root/subversion/tests/libsvn_subr/stream-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'subversion/tests/libsvn_subr/stream-test.c')
-rw-r--r--subversion/tests/libsvn_subr/stream-test.c124
1 files changed, 104 insertions, 20 deletions
diff --git a/subversion/tests/libsvn_subr/stream-test.c b/subversion/tests/libsvn_subr/stream-test.c
index c8dba13..aaa9bf1 100644
--- a/subversion/tests/libsvn_subr/stream-test.c
+++ b/subversion/tests/libsvn_subr/stream-test.c
@@ -73,7 +73,7 @@ test_stream_from_string(apr_pool_t *pool)
while (len == TEST_BUF_SIZE)
{
/* Read a chunk ... */
- SVN_ERR(svn_stream_read(stream, buffer, &len));
+ SVN_ERR(svn_stream_read_full(stream, buffer, &len));
/* ... and append the chunk to the stringbuf. */
svn_stringbuf_appendbytes(outbuf, buffer, len);
@@ -206,7 +206,7 @@ test_stream_compressed(apr_pool_t *pool)
while (len >= TEST_BUF_SIZE)
{
len = TEST_BUF_SIZE;
- SVN_ERR(svn_stream_read(stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(stream, buf, &len));
if (len > 0)
svn_stringbuf_appendbytes(inbuf, buf, len);
}
@@ -332,17 +332,17 @@ test_stream_seek_stringbuf(apr_pool_t *pool)
stringbuf = svn_stringbuf_create("OneTwo", pool);
stream = svn_stream_from_stringbuf(stringbuf, pool);
len = 3;
- SVN_ERR(svn_stream_read(stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(stream, buf, &len));
buf[3] = '\0';
SVN_TEST_STRING_ASSERT(buf, "One");
SVN_ERR(svn_stream_mark(stream, &mark, pool));
len = 3;
- SVN_ERR(svn_stream_read(stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(stream, buf, &len));
buf[3] = '\0';
SVN_TEST_STRING_ASSERT(buf, "Two");
SVN_ERR(svn_stream_seek(stream, mark));
len = 3;
- SVN_ERR(svn_stream_read(stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(stream, buf, &len));
buf[3] = '\0';
SVN_TEST_STRING_ASSERT(buf, "Two");
@@ -351,7 +351,7 @@ test_stream_seek_stringbuf(apr_pool_t *pool)
SVN_ERR(svn_stream_skip(stream, 2));
/* The remaining line should be empty */
len = 3;
- SVN_ERR(svn_stream_read(stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(stream, buf, &len));
buf[len] = '\0';
SVN_TEST_ASSERT(len == 1);
SVN_TEST_STRING_ASSERT(buf, "o");
@@ -381,7 +381,7 @@ test_stream_seek_translated(apr_pool_t *pool)
FALSE, keywords, TRUE, pool);
/* Seek from outside of keyword to inside of keyword. */
len = 25;
- SVN_ERR(svn_stream_read(translated_stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
SVN_TEST_ASSERT(len == 25);
buf[25] = '\0';
SVN_TEST_STRING_ASSERT(buf, "One$MyKeyword: my keyword");
@@ -389,7 +389,7 @@ test_stream_seek_translated(apr_pool_t *pool)
SVN_ERR(svn_stream_reset(translated_stream));
SVN_ERR(svn_stream_seek(translated_stream, mark));
len = 4;
- SVN_ERR(svn_stream_read(translated_stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
SVN_TEST_ASSERT(len == 4);
buf[4] = '\0';
SVN_TEST_STRING_ASSERT(buf, " was");
@@ -397,7 +397,7 @@ test_stream_seek_translated(apr_pool_t *pool)
SVN_ERR(svn_stream_seek(translated_stream, mark));
SVN_ERR(svn_stream_skip(translated_stream, 2));
len = 2;
- SVN_ERR(svn_stream_read(translated_stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
SVN_TEST_ASSERT(len == 2);
buf[len] = '\0';
SVN_TEST_STRING_ASSERT(buf, "as");
@@ -405,13 +405,13 @@ test_stream_seek_translated(apr_pool_t *pool)
/* Seek from inside of keyword to inside of keyword. */
SVN_ERR(svn_stream_mark(translated_stream, &mark, pool));
len = 9;
- SVN_ERR(svn_stream_read(translated_stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
SVN_TEST_ASSERT(len == 9);
buf[9] = '\0';
SVN_TEST_STRING_ASSERT(buf, " expanded");
SVN_ERR(svn_stream_seek(translated_stream, mark));
len = 9;
- SVN_ERR(svn_stream_read(translated_stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
SVN_TEST_ASSERT(len == 9);
buf[9] = '\0';
SVN_TEST_STRING_ASSERT(buf, " expanded");
@@ -419,7 +419,7 @@ test_stream_seek_translated(apr_pool_t *pool)
SVN_ERR(svn_stream_seek(translated_stream, mark));
SVN_ERR(svn_stream_skip(translated_stream, 6));
len = 3;
- SVN_ERR(svn_stream_read(translated_stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
SVN_TEST_ASSERT(len == 3);
buf[len] = '\0';
SVN_TEST_STRING_ASSERT(buf, "ded");
@@ -427,13 +427,13 @@ test_stream_seek_translated(apr_pool_t *pool)
/* Seek from inside of keyword to outside of keyword. */
SVN_ERR(svn_stream_mark(translated_stream, &mark, pool));
len = 4;
- SVN_ERR(svn_stream_read(translated_stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
SVN_TEST_ASSERT(len == 4);
buf[4] = '\0';
SVN_TEST_STRING_ASSERT(buf, " $Tw");
SVN_ERR(svn_stream_seek(translated_stream, mark));
len = 4;
- SVN_ERR(svn_stream_read(translated_stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
SVN_TEST_ASSERT(len == 4);
buf[4] = '\0';
SVN_TEST_STRING_ASSERT(buf, " $Tw");
@@ -441,7 +441,7 @@ test_stream_seek_translated(apr_pool_t *pool)
SVN_ERR(svn_stream_seek(translated_stream, mark));
SVN_ERR(svn_stream_skip(translated_stream, 2));
len = 2;
- SVN_ERR(svn_stream_read(translated_stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
SVN_TEST_ASSERT(len == 2);
buf[len] = '\0';
SVN_TEST_STRING_ASSERT(buf, "Tw");
@@ -449,13 +449,13 @@ test_stream_seek_translated(apr_pool_t *pool)
/* Seek from outside of keyword to outside of keyword. */
SVN_ERR(svn_stream_mark(translated_stream, &mark, pool));
len = 1;
- SVN_ERR(svn_stream_read(translated_stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
SVN_TEST_ASSERT(len == 1);
buf[1] = '\0';
SVN_TEST_STRING_ASSERT(buf, "o");
SVN_ERR(svn_stream_seek(translated_stream, mark));
len = 1;
- SVN_ERR(svn_stream_read(translated_stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
SVN_TEST_ASSERT(len == 1);
buf[1] = '\0';
SVN_TEST_STRING_ASSERT(buf, "o");
@@ -463,7 +463,7 @@ test_stream_seek_translated(apr_pool_t *pool)
SVN_ERR(svn_stream_seek(translated_stream, mark));
SVN_ERR(svn_stream_skip(translated_stream, 2));
len = 1;
- SVN_ERR(svn_stream_read(translated_stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
SVN_TEST_ASSERT(len == 0);
buf[len] = '\0';
SVN_TEST_STRING_ASSERT(buf, "");
@@ -524,7 +524,7 @@ test_stream_compressed_empty_file(apr_pool_t *pool)
pool, pool));
stream = svn_stream_compressed(empty_file_stream, pool);
len = sizeof(buf);
- SVN_ERR(svn_stream_read(stream, buf, &len));
+ SVN_ERR(svn_stream_read_full(stream, buf, &len));
if (len > 0)
return svn_error_create(SVN_ERR_TEST_FAILED, NULL,
"Got unexpected result.");
@@ -727,9 +727,87 @@ test_stream_base64_2(apr_pool_t *pool)
return SVN_NO_ERROR;
}
+static svn_error_t *
+test_stringbuf_from_stream(apr_pool_t *pool)
+{
+ const char *test_cases[] =
+ {
+ "",
+ "x",
+ "this string is longer than the default 64 minimum block size used"
+ "by the function under test",
+ NULL
+ };
+
+ const char **test_case;
+ for (test_case = test_cases; *test_case; ++test_case)
+ {
+ svn_stringbuf_t *result1, *result2, *result3, *result4;
+ svn_stringbuf_t *original = svn_stringbuf_create(*test_case, pool);
+
+ svn_stream_t *stream1 = svn_stream_from_stringbuf(original, pool);
+ svn_stream_t *stream2 = svn_stream_from_stringbuf(original, pool);
+
+ SVN_ERR(svn_stringbuf_from_stream(&result1, stream1, 0, pool));
+ SVN_ERR(svn_stringbuf_from_stream(&result2, stream1, 0, pool));
+ SVN_ERR(svn_stringbuf_from_stream(&result3, stream2, original->len,
+ pool));
+ SVN_ERR(svn_stringbuf_from_stream(&result4, stream2, original->len,
+ pool));
+
+ /* C-string contents must match */
+ SVN_TEST_STRING_ASSERT(result1->data, original->data);
+ SVN_TEST_STRING_ASSERT(result2->data, "");
+ SVN_TEST_STRING_ASSERT(result3->data, original->data);
+ SVN_TEST_STRING_ASSERT(result4->data, "");
+
+ /* assumed length must match */
+ SVN_TEST_ASSERT(result1->len == original->len);
+ SVN_TEST_ASSERT(result2->len == 0);
+ SVN_TEST_ASSERT(result3->len == original->len);
+ SVN_TEST_ASSERT(result4->len == 0);
+ }
+
+ return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+empty_read_full_fn(void *baton, char *buffer, apr_size_t *len)
+{
+ *len = 0;
+ return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+test_stream_compressed_read_full(apr_pool_t *pool)
+{
+ svn_stream_t *stream, *empty_stream;
+ char buf[1];
+ apr_size_t len;
+
+ /* Reading an empty stream with read_full only support should not error. */
+ empty_stream = svn_stream_create(NULL, pool);
+
+ /* Create stream with only full read support. */
+ svn_stream_set_read2(empty_stream, NULL, empty_read_full_fn);
+
+ stream = svn_stream_compressed(empty_stream, pool);
+ len = sizeof(buf);
+ SVN_ERR(svn_stream_read_full(stream, buf, &len));
+ if (len > 0)
+ return svn_error_create(SVN_ERR_TEST_FAILED, NULL,
+ "Got unexpected result.");
+
+ SVN_ERR(svn_stream_close(stream));
+
+ return SVN_NO_ERROR;
+}
+
/* The test table. */
-struct svn_test_descriptor_t test_funcs[] =
+static int max_threads = 1;
+
+static struct svn_test_descriptor_t test_funcs[] =
{
SVN_TEST_NULL,
SVN_TEST_PASS2(test_stream_from_string,
@@ -752,5 +830,11 @@ struct svn_test_descriptor_t test_funcs[] =
"test base64 encoding/decoding streams"),
SVN_TEST_PASS2(test_stream_base64_2,
"base64 decoding allocation problem"),
+ SVN_TEST_PASS2(test_stringbuf_from_stream,
+ "test svn_stringbuf_from_stream"),
+ SVN_TEST_PASS2(test_stream_compressed_read_full,
+ "test compression for streams without partial read"),
SVN_TEST_NULL
};
+
+SVN_TEST_MAIN