subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gst...@apache.org
Subject svn commit: r1173153 - /subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c
Date Tue, 20 Sep 2011 13:56:04 GMT
Author: gstein
Date: Tue Sep 20 13:56:03 2011
New Revision: 1173153

URL: http://svn.apache.org/viewvc?rev=1173153&view=rev
Log:
Add another test to validate some of the behavior of reading from the
spill file.

* subversion/tests/libsvn_subr/spillbuf-test.c:
  (basic_data): extracted from test_spillbuf_basic's DATA localvar
  (test_spillbuf_basic): move DATA to global. add a final empty test.
  (test_spillbuf_file): add a test for the reading behavior of the file:
    it will read BLOCKSIZE data rather than hunks corresponding to the
    size of the original writes. in-memory blocks will retain the original
    write sizes.
  (test_funcs): add the new test

Modified:
    subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c

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=1173153&r1=1173152&r2=1173153&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c Tue Sep 20 13:56:03 2011
@@ -28,15 +28,18 @@
 #include "../svn_test.h"
 
 
+static const char basic_data[] = ("abcdefghijklmnopqrstuvwxyz"
+                                  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+                                  "0123456789");
+
+
 static svn_error_t *
 test_spillbuf_basic(apr_pool_t *pool)
 {
-  static const char data[] = ("abcdefghijklmnopqrstuvwxyz"
-                              "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-                              "0123456789");
-  svn_spillbuf_t *buf = svn_spillbuf_create(sizeof(data) /* blocksize */,
-                                            10 * sizeof(data) /* maxsize */,
-                                            pool);
+  svn_spillbuf_t *buf = svn_spillbuf_create(
+                          sizeof(basic_data) /* blocksize */,
+                          10 * sizeof(basic_data) /* maxsize */,
+                          pool);
   int i;
 
   /* It starts empty.  */
@@ -44,7 +47,7 @@ test_spillbuf_basic(apr_pool_t *pool)
 
   /* Place enough data into the buffer to cause a spill to disk.  */
   for (i = 20; i--; )
-    SVN_ERR(svn_spillbuf_write(buf, data, sizeof(data), pool));
+    SVN_ERR(svn_spillbuf_write(buf, basic_data, sizeof(basic_data), pool));
 
   /* And now has content.  */
   SVN_TEST_ASSERT(!svn_spillbuf_is_empty(buf));
@@ -60,19 +63,89 @@ test_spillbuf_basic(apr_pool_t *pool)
 
       /* We happen to know that the spill buffer reads data in lengths
          of BLOCKSIZE.  */
-      SVN_TEST_ASSERT(readlen == sizeof(data));
+      SVN_TEST_ASSERT(readlen == sizeof(basic_data));
 
       /* And it should match each block of data we put in.  */
-      SVN_TEST_ASSERT(memcmp(readptr, data, readlen) == 0);
+      SVN_TEST_ASSERT(memcmp(readptr, basic_data, readlen) == 0);
+    }
+
+  SVN_TEST_ASSERT(svn_spillbuf_is_empty(buf));
+
+  return SVN_NO_ERROR;
+}
+
+
+static svn_error_t *
+test_spillbuf_file(apr_pool_t *pool)
+{
+  svn_spillbuf_t *buf = svn_spillbuf_create(
+                          sizeof(basic_data) + 2 /* blocksize */,
+                          2 * sizeof(basic_data) /* maxsize */,
+                          pool);
+  int i;
+  const char *readptr;
+  apr_size_t readlen;
+  int cur_index;
+
+  /* Place enough data into the buffer to cause a spill to disk. Note that
+     we are writing data that is *smaller* than the blocksize.  */
+  for (i = 7; i--; )
+    SVN_ERR(svn_spillbuf_write(buf, basic_data, sizeof(basic_data), pool));
+
+  /* The first three reads will be in-memory blocks, so they will match
+     what we wrote into the spill buffer.  */
+  SVN_ERR(svn_spillbuf_read(&readptr, &readlen, buf, pool));
+  SVN_TEST_ASSERT(readptr != NULL);
+  SVN_TEST_ASSERT(readlen == sizeof(basic_data));
+  SVN_ERR(svn_spillbuf_read(&readptr, &readlen, buf, pool));
+  SVN_TEST_ASSERT(readptr != NULL);
+  SVN_TEST_ASSERT(readlen == sizeof(basic_data));
+  SVN_ERR(svn_spillbuf_read(&readptr, &readlen, buf, pool));
+  SVN_TEST_ASSERT(readptr != NULL);
+  SVN_TEST_ASSERT(readlen == sizeof(basic_data));
+
+  /* Current index into basic_data[] that we compare against.  */
+  cur_index = 0;
+
+  while (TRUE)
+    {
+      /* This will read more bytes (from the spill file into a temporary
+         in-memory block) than the blocks of data that we wrote. This makes
+         it trickier to verify that the right data is being returned.  */
+      SVN_ERR(svn_spillbuf_read(&readptr, &readlen, buf, pool));
+      if (readptr == NULL)
+        break;
+
+      while (TRUE)
+        {
+          apr_size_t amt;
+
+          /* Compute the slice of basic_data that we will compare against,
+             given the readlen and cur_index.  */
+          if (cur_index + readlen >= sizeof(basic_data))
+            amt = sizeof(basic_data) - cur_index;
+          else
+            amt = readlen;
+          SVN_TEST_ASSERT(memcmp(readptr, &basic_data[cur_index], amt) == 0);
+          if ((cur_index += amt) == sizeof(basic_data))
+            cur_index = 0;
+          if ((readlen -= amt) == 0)
+            break;
+          readptr += amt;
+        }
     }
 
+  SVN_TEST_ASSERT(svn_spillbuf_is_empty(buf));
+
   return SVN_NO_ERROR;
 }
 
+
 /* The test table.  */
 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_file, "spill buffer file test"),
     SVN_TEST_NULL
   };



Mime
View raw message