diff options
Diffstat (limited to 'subversion/tests/libsvn_subr/spillbuf-test.c')
-rw-r--r-- | subversion/tests/libsvn_subr/spillbuf-test.c | 243 |
1 files changed, 203 insertions, 40 deletions
diff --git a/subversion/tests/libsvn_subr/spillbuf-test.c b/subversion/tests/libsvn_subr/spillbuf-test.c index c928dc3..16021b1 100644 --- a/subversion/tests/libsvn_subr/spillbuf-test.c +++ b/subversion/tests/libsvn_subr/spillbuf-test.c @@ -57,10 +57,8 @@ check_read(svn_spillbuf_t *buf, static svn_error_t * -test_spillbuf_basic(apr_pool_t *pool) +test_spillbuf__basic(apr_pool_t *pool, apr_size_t len, svn_spillbuf_t *buf) { - apr_size_t len = strlen(basic_data); /* Don't include basic_data's NUL */ - svn_spillbuf_t *buf = svn_spillbuf__create(len, 10 * len, pool); int i; const char *readptr; apr_size_t readlen; @@ -87,6 +85,22 @@ test_spillbuf_basic(apr_pool_t *pool) return SVN_NO_ERROR; } +static svn_error_t * +test_spillbuf_basic(apr_pool_t *pool) +{ + apr_size_t len = strlen(basic_data); /* Don't include basic_data's NUL */ + svn_spillbuf_t *buf = svn_spillbuf__create(len, 10 * len, pool); + return test_spillbuf__basic(pool, len, buf); +} + +static svn_error_t * +test_spillbuf_basic_spill_all(apr_pool_t *pool) +{ + apr_size_t len = strlen(basic_data); /* Don't include basic_data's NUL */ + svn_spillbuf_t *buf = + svn_spillbuf__create_extended(len, 10 * len, TRUE, TRUE, NULL, pool); + return test_spillbuf__basic(pool, len, buf); +} static svn_error_t * read_callback(svn_boolean_t *stop, @@ -107,12 +121,8 @@ read_callback(svn_boolean_t *stop, static svn_error_t * -test_spillbuf_callback(apr_pool_t *pool) +test_spillbuf__callback(apr_pool_t *pool, svn_spillbuf_t *buf) { - svn_spillbuf_t *buf = svn_spillbuf__create( - sizeof(basic_data) /* blocksize */, - 10 * sizeof(basic_data) /* maxsize */, - pool); int i; int counter; svn_boolean_t exhausted; @@ -133,15 +143,31 @@ test_spillbuf_callback(apr_pool_t *pool) return SVN_NO_ERROR; } - static svn_error_t * -test_spillbuf_file(apr_pool_t *pool) +test_spillbuf_callback(apr_pool_t *pool) { - apr_size_t altsize = sizeof(basic_data) + 2; svn_spillbuf_t *buf = svn_spillbuf__create( - altsize /* blocksize */, - 2 * sizeof(basic_data) /* maxsize */, + sizeof(basic_data) /* blocksize */, + 10 * sizeof(basic_data) /* maxsize */, pool); + return test_spillbuf__callback(pool, buf); +} + +static svn_error_t * +test_spillbuf_callback_spill_all(apr_pool_t *pool) +{ + svn_spillbuf_t *buf = svn_spillbuf__create_extended( + sizeof(basic_data) /* blocksize */, + 10 * sizeof(basic_data) /* maxsize */, + TRUE /* delte on close */, + TRUE /* spill all data */, + NULL, pool); + return test_spillbuf__callback(pool, buf); +} + +static svn_error_t * +test_spillbuf__file(apr_pool_t *pool, apr_size_t altsize, svn_spillbuf_t *buf) +{ int i; const char *readptr; apr_size_t readlen; @@ -203,14 +229,33 @@ test_spillbuf_file(apr_pool_t *pool) return SVN_NO_ERROR; } +static svn_error_t * +test_spillbuf_file(apr_pool_t *pool) +{ + apr_size_t altsize = sizeof(basic_data) + 2; + svn_spillbuf_t *buf = svn_spillbuf__create( + altsize /* blocksize */, + 2 * sizeof(basic_data) /* maxsize */, + pool); + return test_spillbuf__file(pool, altsize, buf); +} static svn_error_t * -test_spillbuf_interleaving(apr_pool_t *pool) +test_spillbuf_file_spill_all(apr_pool_t *pool) { - svn_spillbuf_t *buf = svn_spillbuf__create(8 /* blocksize */, - 15 /* maxsize */, - pool); + apr_size_t altsize = sizeof(basic_data) + 2; + svn_spillbuf_t *buf = svn_spillbuf__create_extended( + altsize /* blocksize */, + 2 * sizeof(basic_data) /* maxsize */, + TRUE /* delte on close */, + TRUE /* spill all data */, + NULL, pool); + return test_spillbuf__file(pool, altsize, buf); +} +static svn_error_t * +test_spillbuf__interleaving(apr_pool_t *pool, svn_spillbuf_t* buf) +{ SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool)); SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool)); /* now: two blocks: 8 and 4 bytes */ @@ -238,18 +283,36 @@ test_spillbuf_interleaving(apr_pool_t *pool) return SVN_NO_ERROR; } +static svn_error_t * +test_spillbuf_interleaving(apr_pool_t *pool) +{ + svn_spillbuf_t *buf = svn_spillbuf__create(8 /* blocksize */, + 15 /* maxsize */, + pool); + return test_spillbuf__interleaving(pool, buf); +} + +static svn_error_t * +test_spillbuf_interleaving_spill_all(apr_pool_t *pool) +{ + svn_spillbuf_t *buf = svn_spillbuf__create_extended( + 8 /* blocksize */, + 15 /* maxsize */, + TRUE /* delte on close */, + TRUE /* spill all data */, + NULL, pool); + return test_spillbuf__interleaving(pool, buf); +} static svn_error_t * test_spillbuf_reader(apr_pool_t *pool) { - svn_spillbuf_reader_t *sbr; + svn_spillbuf_reader_t *sbr = svn_spillbuf__reader_create(4 /* blocksize */, + 100 /* maxsize */, + pool); apr_size_t amt; char buf[10]; - sbr = svn_spillbuf__reader_create(4 /* blocksize */, - 100 /* maxsize */, - pool); - SVN_ERR(svn_spillbuf__reader_write(sbr, "abcdef", 6, pool)); /* Get a buffer from the underlying reader, and grab a couple bytes. */ @@ -270,13 +333,13 @@ test_spillbuf_reader(apr_pool_t *pool) return SVN_NO_ERROR; } - static svn_error_t * test_spillbuf_stream(apr_pool_t *pool) { - svn_stream_t *stream = svn_stream__from_spillbuf(8 /* blocksize */, - 15 /* maxsize */, - pool); + svn_spillbuf_t *buf = svn_spillbuf__create(4 /* blocksize */, + 100 /* maxsize */, + pool); + svn_stream_t *stream = svn_stream__from_spillbuf(buf, pool); char readbuf[256]; apr_size_t readlen; apr_size_t writelen; @@ -287,7 +350,7 @@ test_spillbuf_stream(apr_pool_t *pool) /* now: two blocks: 8 and 4 bytes */ readlen = 8; - SVN_ERR(svn_stream_read(stream, readbuf, &readlen)); + SVN_ERR(svn_stream_read_full(stream, readbuf, &readlen)); SVN_TEST_ASSERT(readlen == 8 && memcmp(readbuf, "abcdefgh", 8) == 0); /* now: one block: 4 bytes */ @@ -295,7 +358,7 @@ test_spillbuf_stream(apr_pool_t *pool) SVN_ERR(svn_stream_write(stream, "mnopqr", &writelen)); /* now: two blocks: 8 and 2 bytes */ - SVN_ERR(svn_stream_read(stream, readbuf, &readlen)); + SVN_ERR(svn_stream_read_full(stream, readbuf, &readlen)); SVN_TEST_ASSERT(readlen == 8 && memcmp(readbuf, "ijklmnop", 8) == 0); /* now: one block: 2 bytes */ @@ -305,28 +368,23 @@ test_spillbuf_stream(apr_pool_t *pool) SVN_ERR(svn_stream_write(stream, "GHIJKL", &writelen)); /* now: two blocks: 8 and 6 bytes, and 6 bytes spilled to a file */ - SVN_ERR(svn_stream_read(stream, readbuf, &readlen)); + SVN_ERR(svn_stream_read_full(stream, readbuf, &readlen)); SVN_TEST_ASSERT(readlen == 8 && memcmp(readbuf, "qrstuvwx", 8) == 0); readlen = 6; - SVN_ERR(svn_stream_read(stream, readbuf, &readlen)); + SVN_ERR(svn_stream_read_full(stream, readbuf, &readlen)); SVN_TEST_ASSERT(readlen == 6 && memcmp(readbuf, "ABCDEF", 6) == 0); - SVN_ERR(svn_stream_read(stream, readbuf, &readlen)); + SVN_ERR(svn_stream_read_full(stream, readbuf, &readlen)); SVN_TEST_ASSERT(readlen == 6 && memcmp(readbuf, "GHIJKL", 6) == 0); return SVN_NO_ERROR; } - static svn_error_t * -test_spillbuf_rwfile(apr_pool_t *pool) +test_spillbuf__rwfile(apr_pool_t *pool, svn_spillbuf_t *buf) { - svn_spillbuf_t *buf = svn_spillbuf__create(4 /* blocksize */, - 10 /* maxsize */, - pool); - SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool)); SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool)); SVN_ERR(svn_spillbuf__write(buf, "mnopqr", 6, pool)); @@ -360,14 +418,30 @@ test_spillbuf_rwfile(apr_pool_t *pool) return SVN_NO_ERROR; } - static svn_error_t * -test_spillbuf_eof(apr_pool_t *pool) +test_spillbuf_rwfile(apr_pool_t *pool) { svn_spillbuf_t *buf = svn_spillbuf__create(4 /* blocksize */, 10 /* maxsize */, pool); + return test_spillbuf__rwfile(pool, buf); +} + +static svn_error_t * +test_spillbuf_rwfile_spill_all(apr_pool_t *pool) +{ + svn_spillbuf_t *buf = svn_spillbuf__create_extended( + 4 /* blocksize */, + 10 /* maxsize */, + TRUE /* delte on close */, + TRUE /* spill all data */, + NULL, pool); + return test_spillbuf__rwfile(pool, buf); +} +static svn_error_t * +test_spillbuf__eof(apr_pool_t *pool, svn_spillbuf_t *buf) +{ SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool)); SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool)); /* now: two blocks: 4 and 2 bytes, and 6 bytes in spill file. */ @@ -415,19 +489,108 @@ test_spillbuf_eof(apr_pool_t *pool) return SVN_NO_ERROR; } +static svn_error_t * +test_spillbuf_eof(apr_pool_t *pool) +{ + svn_spillbuf_t *buf = svn_spillbuf__create(4 /* blocksize */, + 10 /* maxsize */, + pool); + return test_spillbuf__eof(pool, buf); +} + +static svn_error_t * +test_spillbuf_eof_spill_all(apr_pool_t *pool) +{ + svn_spillbuf_t *buf = svn_spillbuf__create_extended( + 4 /* blocksize */, + 10 /* maxsize */, + TRUE /* delte on close */, + TRUE /* spill all data */, + NULL, pool); + return test_spillbuf__eof(pool, buf); +} + +static svn_error_t * +test_spillbuf__file_attrs(apr_pool_t *pool, svn_boolean_t spill_all, + svn_spillbuf_t *buf) +{ + apr_finfo_t finfo; + + SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool)); + SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool)); + SVN_ERR(svn_spillbuf__write(buf, "mnopqr", 6, pool)); + + /* Check that the spillbuf size is what we expect it to be */ + SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == 18); + + /* Check file existence */ + SVN_TEST_ASSERT(svn_spillbuf__get_filename(buf) != NULL); + SVN_TEST_ASSERT(svn_spillbuf__get_file(buf) != NULL); + + /* The size of the file must match expectations */ + SVN_ERR(svn_io_file_info_get(&finfo, APR_FINFO_SIZE, + svn_spillbuf__get_file(buf), pool)); + if (spill_all) + SVN_TEST_ASSERT(finfo.size == svn_spillbuf__get_size(buf)); + else + SVN_TEST_ASSERT(finfo.size == (svn_spillbuf__get_size(buf) + - svn_spillbuf__get_memory_size(buf))); + return SVN_NO_ERROR; +} + +static svn_error_t * +test_spillbuf_file_attrs(apr_pool_t *pool) +{ + svn_spillbuf_t *buf = svn_spillbuf__create(4 /* blocksize */, + 10 /* maxsize */, + pool); + return test_spillbuf__file_attrs(pool, FALSE, buf); +} + +static svn_error_t * +test_spillbuf_file_attrs_spill_all(apr_pool_t *pool) +{ + svn_spillbuf_t *buf = svn_spillbuf__create_extended( + 4 /* blocksize */, + 10 /* maxsize */, + TRUE /* delte on close */, + TRUE /* spill all data */, + NULL, pool); + return test_spillbuf__file_attrs(pool, TRUE, buf); +} /* 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_spillbuf_basic, "basic spill buffer test"), + SVN_TEST_PASS2(test_spillbuf_basic_spill_all, + "basic spill buffer test (spill-all-data)"), SVN_TEST_PASS2(test_spillbuf_callback, "spill buffer read callback"), + SVN_TEST_PASS2(test_spillbuf_callback_spill_all, + "spill buffer read callback (spill-all-data)"), SVN_TEST_PASS2(test_spillbuf_file, "spill buffer file test"), + SVN_TEST_PASS2(test_spillbuf_file_spill_all, + "spill buffer file test (spill-all-data)"), SVN_TEST_PASS2(test_spillbuf_interleaving, "interleaving reads and writes"), + SVN_TEST_PASS2(test_spillbuf_interleaving_spill_all, + "interleaving reads and writes (spill-all-data)"), SVN_TEST_PASS2(test_spillbuf_reader, "spill buffer reader test"), SVN_TEST_PASS2(test_spillbuf_stream, "spill buffer stream test"), SVN_TEST_PASS2(test_spillbuf_rwfile, "read/write spill file"), + SVN_TEST_PASS2(test_spillbuf_rwfile_spill_all, + "read/write spill file (spill-all-data)"), SVN_TEST_PASS2(test_spillbuf_eof, "validate reaching EOF of spill file"), + SVN_TEST_PASS2(test_spillbuf_eof_spill_all, + "validate reaching EOF (spill-all-data)"), + SVN_TEST_PASS2(test_spillbuf_file_attrs, "check spill file properties"), + SVN_TEST_PASS2(test_spillbuf_file_attrs_spill_all, + "check spill file properties (spill-all-data)"), SVN_TEST_NULL }; + +SVN_TEST_MAIN |