subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@apache.org
Subject svn commit: r1617144 - /subversion/branches/authzperf/subversion/tests/libsvn_subr/string-test.c
Date Sun, 10 Aug 2014 19:08:52 GMT
Author: stefan2
Date: Sun Aug 10 19:08:52 2014
New Revision: 1617144

URL: http://svn.apache.org/r1617144
Log:
On the authzperf branch: Provide a test for svn_stringbuf_replace_all.

* subversion/tests/libsvn_subr/string-test.c
  (test_stringbuf_replace_all): New test.
  (test_funcs): Register new test.

Modified:
    subversion/branches/authzperf/subversion/tests/libsvn_subr/string-test.c

Modified: subversion/branches/authzperf/subversion/tests/libsvn_subr/string-test.c
URL: http://svn.apache.org/viewvc/subversion/branches/authzperf/subversion/tests/libsvn_subr/string-test.c?rev=1617144&r1=1617143&r2=1617144&view=diff
==============================================================================
--- subversion/branches/authzperf/subversion/tests/libsvn_subr/string-test.c (original)
+++ subversion/branches/authzperf/subversion/tests/libsvn_subr/string-test.c Sun Aug 10 19:08:52
2014
@@ -846,6 +846,64 @@ test_string_skip_prefix(apr_pool_t *pool
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+test_stringbuf_replace_all(apr_pool_t *pool)
+{
+  svn_stringbuf_t *s = svn_stringbuf_create("abccabcdabc", pool);
+
+  /* no replacement */
+  SVN_TEST_ASSERT(0 == svn_stringbuf_replace_all(s, "xyz", "k"));
+  SVN_TEST_STRING_ASSERT(s->data, "abccabcdabc");
+  SVN_TEST_ASSERT(s->len == 11);
+
+  /* replace at string head: grow */
+  SVN_TEST_ASSERT(1 == svn_stringbuf_replace_all(s, "abcc", "xyabcz"));
+  SVN_TEST_STRING_ASSERT(s->data, "xyabczabcdabc");
+  SVN_TEST_ASSERT(s->len == 13);
+
+  /* replace at string head: shrink */
+  SVN_TEST_ASSERT(1 == svn_stringbuf_replace_all(s, "xyabcz", "abcc"));
+  SVN_TEST_STRING_ASSERT(s->data, "abccabcdabc");
+  SVN_TEST_ASSERT(s->len == 11);
+
+  /* replace at string tail: grow */
+  SVN_TEST_ASSERT(1 == svn_stringbuf_replace_all(s, "dabc", "xyabcz"));
+  SVN_TEST_STRING_ASSERT(s->data, "abccabcxyabcz");
+  SVN_TEST_ASSERT(s->len == 13);
+
+  /* replace at string tail: shrink */
+  SVN_TEST_ASSERT(1 == svn_stringbuf_replace_all(s, "xyabcz", "dabc"));
+  SVN_TEST_STRING_ASSERT(s->data, "abccabcdabc");
+  SVN_TEST_ASSERT(s->len == 11);
+
+  /* replace at multiple locations: grow */
+  SVN_TEST_ASSERT(3 == svn_stringbuf_replace_all(s, "ab", "xyabz"));
+  SVN_TEST_STRING_ASSERT(s->data, "xyabzccxyabzcdxyabzc");
+  SVN_TEST_ASSERT(s->len == 20);
+
+  /* replace at multiple locations: shrink */
+  SVN_TEST_ASSERT(3 == svn_stringbuf_replace_all(s, "xyabz", "ab"));
+  SVN_TEST_STRING_ASSERT(s->data, "abccabcdabc");
+  SVN_TEST_ASSERT(s->len == 11);
+
+  /* replace at multiple locations: same length */
+  SVN_TEST_ASSERT(3 == svn_stringbuf_replace_all(s, "abc", "xyz"));
+  SVN_TEST_STRING_ASSERT(s->data, "xyzcxyzdxyz");
+  SVN_TEST_ASSERT(s->len == 11);
+
+  /* replace at multiple locations: overlapping */
+  s = svn_stringbuf_create("aaaaaaaaaaa", pool);
+  SVN_TEST_ASSERT(5 == svn_stringbuf_replace_all(s, "aa", "aaa"));
+  SVN_TEST_STRING_ASSERT(s->data, "aaaaaaaaaaaaaaaa");
+  SVN_TEST_ASSERT(s->len == 16);
+
+  SVN_TEST_ASSERT(5 == svn_stringbuf_replace_all(s, "aaa", "aa"));
+  SVN_TEST_STRING_ASSERT(s->data, "aaaaaaaaaaa");
+  SVN_TEST_ASSERT(s->len == 11);
+
+  return SVN_NO_ERROR;
+}
+
 /*
    ====================================================================
    If you add a new test to this file, update this array.
@@ -922,6 +980,8 @@ static struct svn_test_descriptor_t test
                    "test string matching"),
     SVN_TEST_PASS2(test_string_skip_prefix,
                    "test svn_cstring_skip_prefix()"),
+    SVN_TEST_PASS2(test_stringbuf_replace_all,
+                   "test svn_stringbuf_replace_all"),
     SVN_TEST_NULL
   };
 



Mime
View raw message