[email protected] wrote on Tue, Sep 20, 2011 at 13:29:07 -0000:
> Author: gstein
> Date: Tue Sep 20 13:29:06 2011
> New Revision: 1173137
> 
> URL: http://svn.apache.org/viewvc?rev=1173137&view=rev
> Log:
> Initial test for the new spill buffer code.
> 
> * build.conf:
>   (spillbuf-test): new test. adjust related sections, too.
> 
> * subversion/tests/libsvn_subr:
>   (svn:ignore): ignore spillbuf-test
> 
> * subversion/tests/libsvn_subr/spillbuf-test.c: new test
> 
> Added:
>     subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c
> Modified:
>     subversion/trunk/build.conf
>     subversion/trunk/subversion/tests/libsvn_subr/   (props changed)
> 
> Modified: subversion/trunk/build.conf
> URL: 
> http://svn.apache.org/viewvc/subversion/trunk/build.conf?rev=1173137&r1=1173136&r2=1173137&view=diff
> ==============================================================================
> --- subversion/trunk/build.conf (original)
> +++ subversion/trunk/build.conf Tue Sep 20 13:29:06 2011
> @@ -331,6 +331,7 @@ msvc-export = 
>          private\svn_token.h  private\svn_adler32.h
>          private\svn_temp_serializer.h private\svn_io_private.h
>          private\svn_string_private.h private\svn_magic.h
> +        private\svn_subr_private.h
>  
>  # Working copy management lib
>  [libsvn_wc]
> @@ -798,6 +799,14 @@ sources = skel-test.c
>  install = test
>  libs = libsvn_test libsvn_subr apriconv apr
>  
> +[spillbuf-test]
> +description = Test spillbuf in libsvn_subr
> +type = exe
> +path = subversion/tests/libsvn_subr
> +sources = spillbuf-test.c
> +install = test
> +libs = libsvn_test libsvn_subr apriconv apr
> +
>  [stream-test]
>  description = Test stream library
>  type = exe
> @@ -1115,7 +1124,7 @@ libs = __ALL__
>         strings-reps-test changes-test locks-test repos-test
>         checksum-test compat-test config-test hashdump-test mergeinfo-test
>         opt-test path-test stream-test string-test time-test utf-test
> -       target-test error-test cache-test editor-test
> +       target-test error-test cache-test editor-test spillbuf-test
>         revision-test
>         subst_translate-test
>         translate-test
> 
> Propchange: subversion/trunk/subversion/tests/libsvn_subr/
> ------------------------------------------------------------------------------
> --- svn:ignore (original)
> +++ svn:ignore Tue Sep 20 13:29:06 2011
> @@ -34,3 +34,4 @@ dirent_uri-test
>  auth-test
>  eol-test
>  subst_translate-test
> +spillbuf-test
> 
> Added: 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=1173137&view=auto
> ==============================================================================
> --- subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c (added)
> +++ subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c Tue Sep 20 
> 13:29:06 2011
> @@ -0,0 +1,78 @@
> +/*
> + * spillbuf-test.c : test the spill buffer code
> + *
> + * ====================================================================
> + *    Licensed to the Apache Software Foundation (ASF) under one
> + *    or more contributor license agreements.  See the NOTICE file
> + *    distributed with this work for additional information
> + *    regarding copyright ownership.  The ASF licenses this file
> + *    to you under the Apache License, Version 2.0 (the
> + *    "License"); you may not use this file except in compliance
> + *    with the License.  You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *    Unless required by applicable law or agreed to in writing,
> + *    software distributed under the License is distributed on an
> + *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + *    KIND, either express or implied.  See the License for the
> + *    specific language governing permissions and limitations
> + *    under the License.
> + * ====================================================================
> + */
> +
> +#include "svn_types.h"
> +
> +#include "private/svn_subr_private.h"
> +
> +#include "../svn_test.h"
> +
> +
> +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);
> +  int i;
> +

sizeof(data) == strlen(data)+1.  Did you really mean to use sizeof()
throughout this file?  Or did you mean strlen()?

(That off-by-one might change the semantics of some tests.)

> +  /* It starts empty.  */
> +  SVN_TEST_ASSERT(svn_spillbuf_is_empty(buf));
> +
> +  /* 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));
> +
> +  /* And now has content.  */
> +  SVN_TEST_ASSERT(!svn_spillbuf_is_empty(buf));
> +
> +  while (TRUE)
> +    {
> +      const char *readptr;
> +      apr_size_t readlen;
> +
> +      SVN_ERR(svn_spillbuf_read(&readptr, &readlen, buf, pool));
> +      if (readptr == NULL)
> +        break;
> +
> +      /* We happen to know that the spill buffer reads data in lengths
> +         of BLOCKSIZE.  */
> +      SVN_TEST_ASSERT(readlen == sizeof(data));
> +
> +      /* And it should match each block of data we put in.  */
> +      SVN_TEST_ASSERT(memcmp(readptr, data, readlen) == 0);
> +    }
> +
> +  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_NULL
> +  };
> 
> 

Reply via email to