subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1509137 - in /subversion/trunk/subversion: include/private/svn_subr_private.h libsvn_subr/spillbuf.c tests/libsvn_subr/spillbuf-test.c
Date Thu, 01 Aug 2013 09:15:30 GMT
Author: brane
Date: Thu Aug  1 09:15:30 2013
New Revision: 1509137

URL: http://svn.apache.org/r1509137
Log:
Add some more constructors, accessors and tests for spillbufs.

* subversion/include/private/svn_subr_private.h
  (svn_spillbuf__get_memory_size, svn_spillbuf__get_filename,
   svn_spillbuf__get_file, svn_spillbuf__reader_create_extended,
   svn_stream__from_spillbuf_extended): New functions.
* subversion/libsvn_subr/spillbuf.c
  (svn_spillbuf__get_memory_size, svn_spillbuf__get_filename,
   svn_spillbuf__reader_create_extended): Implement.
  (stream_from_reader): New private helper function.
  (svn_stream__from_spillbuf, svn_stream__from_spillbuf_extended):
   Implement using stream_from_reader.

* subversion/tests/libsvn_subr/spillbuf-test.c
  (test_spillbuf__reader, test_spillbuf_reader_spill_all,
   test_spillbuf__stream, test_spillbuf_stream_spill_all,
   test_spillbuf__file_attrs, test_spillbuf_file_attrs,
   test_spillbuf_file_attrs_spill_all): New tests and helpers.
  (test_funcs): Add new tests.

Modified:
    subversion/trunk/subversion/include/private/svn_subr_private.h
    subversion/trunk/subversion/libsvn_subr/spillbuf.c
    subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c

Modified: subversion/trunk/subversion/include/private/svn_subr_private.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_subr_private.h?rev=1509137&r1=1509136&r2=1509137&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_subr_private.h (original)
+++ subversion/trunk/subversion/include/private/svn_subr_private.h Thu Aug  1 09:15:30 2013
@@ -107,6 +107,19 @@ svn_spillbuf__create_extended(apr_size_t
 svn_filesize_t
 svn_spillbuf__get_size(const svn_spillbuf_t *buf);
 
+/* Determine how much content the spill buffer is caching in memory.  */
+svn_filesize_t
+svn_spillbuf__get_memory_size(const svn_spillbuf_t *buf);
+
+/* Retreive the name of the spill file. The returned value can be NULL
+   if the file has not been created yet. */
+const char *
+svn_spillbuf__get_filename(const svn_spillbuf_t *buf);
+
+/* Retreive the handle of the spill file. The returned value can be
+   NULL if the file has not been created yet. */
+apr_file_t *
+svn_spillbuf__get_file(const svn_spillbuf_t *buf);
 
 /* Write some data into the spill buffer.  */
 svn_error_t *
@@ -166,6 +179,14 @@ svn_spillbuf__reader_create(apr_size_t b
                             apr_size_t maxsize,
                             apr_pool_t *result_pool);
 
+/* Create a spill-buffer with extra parameters, and a reader for it. */
+svn_spillbuf_reader_t *
+svn_spillbuf__reader_create_extended(apr_size_t blocksize,
+                                     apr_size_t maxsize,
+                                     svn_boolean_t delete_on_close,
+                                     svn_boolean_t spill_all_contents,
+                                     const char* dirpath,
+                                     apr_pool_t *result_pool);
 
 /* Read @a len bytes from @a reader into @a data. The number of bytes
    actually read is stored in @a amt. If the content is exhausted, then
@@ -206,6 +227,16 @@ svn_stream_t *
 svn_stream__from_spillbuf(apr_size_t blocksize,
                           apr_size_t maxsize,
                           apr_pool_t *result_pool);
+/* Return a stream built on top of a spillbuf, using the same arguments as
+   svn_spillbuf__create_extended(). */
+svn_stream_t *
+svn_stream__from_spillbuf_extended(apr_size_t blocksize,
+                                   apr_size_t maxsize,
+                                   svn_boolean_t delete_on_close,
+                                   svn_boolean_t spill_all_contents,
+                                   const char* dirpath,
+                                   apr_pool_t *result_pool);
+
 
 /** @} */
 

Modified: subversion/trunk/subversion/libsvn_subr/spillbuf.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/spillbuf.c?rev=1509137&r1=1509136&r2=1509137&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/spillbuf.c (original)
+++ subversion/trunk/subversion/libsvn_subr/spillbuf.c Thu Aug  1 09:15:30 2013
@@ -176,6 +176,23 @@ svn_spillbuf__get_size(const svn_spillbu
   return buf->memory_size + buf->spill_size;
 }
 
+svn_filesize_t
+svn_spillbuf__get_memory_size(const svn_spillbuf_t *buf)
+{
+  return buf->memory_size;
+}
+
+const char *
+svn_spillbuf__get_filename(const svn_spillbuf_t *buf)
+{
+  return buf->temp_path;
+}
+
+apr_file_t *
+svn_spillbuf__get_file(const svn_spillbuf_t *buf)
+{
+  return buf->spill;
+}
 
 /* Get a memblock from the spill-buffer. It will be the block that we
    passed out for reading, come from the free list, or allocated.  */
@@ -514,6 +531,21 @@ svn_spillbuf__reader_create(apr_size_t b
   return sbr;
 }
 
+svn_spillbuf_reader_t *
+svn_spillbuf__reader_create_extended(apr_size_t blocksize,
+                                     apr_size_t maxsize,
+                                     svn_boolean_t delete_on_close,
+                                     svn_boolean_t spill_all_contents,
+                                     const char* dirpath,
+                                     apr_pool_t *result_pool)
+{
+  svn_spillbuf_reader_t *sbr = apr_pcalloc(result_pool, sizeof(*sbr));
+  init_spillbuf_extended(&sbr->buf, blocksize, maxsize,
+                         delete_on_close, spill_all_contents, dirpath,
+                         result_pool);
+  return sbr;
+}
+
 
 svn_error_t *
 svn_spillbuf__reader_read(apr_size_t *amt,
@@ -660,15 +692,14 @@ write_handler_spillbuf(void *baton, cons
 }
 
 
-svn_stream_t *
-svn_stream__from_spillbuf(apr_size_t blocksize,
-                          apr_size_t maxsize,
-                          apr_pool_t *result_pool)
+/* Wrap a spillbuf reader into a stream. */
+static svn_stream_t *
+stream_from_reader(svn_spillbuf_reader_t *reader, apr_pool_t *result_pool)
 {
   svn_stream_t *stream;
   struct spillbuf_baton *sb = apr_palloc(result_pool, sizeof(*sb));
 
-  sb->reader = svn_spillbuf__reader_create(blocksize, maxsize, result_pool);
+  sb->reader = reader;
   sb->scratch_pool = svn_pool_create(result_pool);
 
   stream = svn_stream_create(sb, result_pool);
@@ -678,3 +709,28 @@ svn_stream__from_spillbuf(apr_size_t blo
 
   return stream;
 }
+
+svn_stream_t *
+svn_stream__from_spillbuf(apr_size_t blocksize,
+                          apr_size_t maxsize,
+                          apr_pool_t *result_pool)
+{
+  return stream_from_reader(
+      svn_spillbuf__reader_create(blocksize, maxsize, result_pool),
+      result_pool);
+}
+
+svn_stream_t *
+svn_stream__from_spillbuf_extended(apr_size_t blocksize,
+                                   apr_size_t maxsize,
+                                   svn_boolean_t delete_on_close,
+                                   svn_boolean_t spill_all_contents,
+                                   const char* dirpath,
+                                   apr_pool_t *result_pool)
+{
+  return stream_from_reader(
+      svn_spillbuf__reader_create_extended(
+          blocksize, maxsize, delete_on_close,
+          spill_all_contents, dirpath, result_pool),
+      result_pool);
+}

Modified: subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c?rev=1509137&r1=1509136&r2=1509137&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c Thu Aug  1 09:15:30 2013
@@ -305,16 +305,11 @@ test_spillbuf_interleaving_spill_all(apr
 }
 
 static svn_error_t *
-test_spillbuf_reader(apr_pool_t *pool)
+test_spillbuf__reader(apr_pool_t *pool, svn_spillbuf_reader_t *sbr)
 {
-  svn_spillbuf_reader_t *sbr;
   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.  */
@@ -335,13 +330,30 @@ test_spillbuf_reader(apr_pool_t *pool)
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+test_spillbuf_reader(apr_pool_t *pool)
+{
+  svn_spillbuf_reader_t *sbr = svn_spillbuf__reader_create(4 /* blocksize */,
+                                                           100 /* maxsize */,
+                                                           pool);
+  return test_spillbuf__reader(pool, sbr);
+}
 
 static svn_error_t *
-test_spillbuf_stream(apr_pool_t *pool)
+test_spillbuf_reader_spill_all(apr_pool_t *pool)
+{
+  svn_spillbuf_reader_t *sbr = svn_spillbuf__reader_create_extended(
+                          4 /* blocksize */,
+                          100 /* maxsize */,
+                          TRUE /* delte on close */,
+                          TRUE /* spill all data */,
+                          NULL, pool);
+  return test_spillbuf__reader(pool, sbr);
+}
+
+static svn_error_t *
+test_spillbuf__stream(apr_pool_t *pool, svn_stream_t *stream)
 {
-  svn_stream_t *stream = svn_stream__from_spillbuf(8 /* blocksize */,
-                                                   15 /* maxsize */,
-                                                   pool);
   char readbuf[256];
   apr_size_t readlen;
   apr_size_t writelen;
@@ -385,6 +397,27 @@ test_spillbuf_stream(apr_pool_t *pool)
 }
 
 static svn_error_t *
+test_spillbuf_stream(apr_pool_t *pool)
+{
+  svn_stream_t *stream = svn_stream__from_spillbuf(8 /* blocksize */,
+                                                   15 /* maxsize */,
+                                                   pool);
+  return test_spillbuf__stream(pool, stream);
+}
+
+static svn_error_t *
+test_spillbuf_stream_spill_all(apr_pool_t *pool)
+{
+  svn_stream_t *stream = svn_stream__from_spillbuf_extended(
+                          8 /* blocksize */,
+                          15 /* maxsize */,
+                          TRUE /* delte on close */,
+                          TRUE /* spill all data */,
+                          NULL, pool);
+  return test_spillbuf__stream(pool, stream);
+}
+
+static svn_error_t *
 test_spillbuf__rwfile(apr_pool_t *pool, svn_spillbuf_t *buf)
 {
   SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool));
@@ -512,6 +545,55 @@ test_spillbuf_eof_spill_all(apr_pool_t *
   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[] =
   {
@@ -530,12 +612,19 @@ struct svn_test_descriptor_t test_funcs[
     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_reader_spill_all,
+                   "spill buffer reader test (spill-all-data)"),
     SVN_TEST_PASS2(test_spillbuf_stream, "spill buffer stream test"),
+    SVN_TEST_PASS2(test_spillbuf_stream_spill_all,
+                   "spill buffer stream test (spill-all-data)"),
     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
   };



Mime
View raw message