Author: stefan2
Date: Tue Jul 30 13:55:16 2013
New Revision: 1508441
URL: http://svn.apache.org/r1508441
Log:
On the fsx branch: add a test for the svn_prefix_string_* API.
* build.conf
(prefix-string-test): declare new target
(__ALL_TESTS__): register new target
* subversion/tests/libsvn_subr/prefix-string-test.c
(): new file
Added:
subversion/branches/fsx/subversion/tests/libsvn_subr/prefix-string-test.c
Modified:
subversion/branches/fsx/build.conf
Modified: subversion/branches/fsx/build.conf
URL:
http://svn.apache.org/viewvc/subversion/branches/fsx/build.conf?rev=1508441&r1=1508440&r2=1508441&view=diff
==============================================================================
--- subversion/branches/fsx/build.conf (original)
+++ subversion/branches/fsx/build.conf Tue Jul 30 13:55:16 2013
@@ -954,6 +954,14 @@ sources = path-test.c
install = test
libs = libsvn_test libsvn_subr apriconv apr
+[prefix-string-test]
+description = Test path library
+type = exe
+path = subversion/tests/libsvn_subr
+sources = prefix-string-test.c
+install = test
+libs = libsvn_test libsvn_subr apriconv apr
+
[revision-test]
description = Test revision library
type = exe
@@ -1332,7 +1340,8 @@ libs = __ALL__
string-table-test
skel-test 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
+ opt-test path-test prefix-string-teststream-test string-test
+ time-test utf-test
error-test error-code-test cache-test spillbuf-test crypto-test
named_atomic-test named_atomic-proc-test revision-test
subst_translate-test io-test
Added: subversion/branches/fsx/subversion/tests/libsvn_subr/prefix-string-test.c
URL:
http://svn.apache.org/viewvc/subversion/branches/fsx/subversion/tests/libsvn_subr/prefix-string-test.c?rev=1508441&view=auto
==============================================================================
--- subversion/branches/fsx/subversion/tests/libsvn_subr/prefix-string-test.c
(added)
+++ subversion/branches/fsx/subversion/tests/libsvn_subr/prefix-string-test.c
Tue Jul 30 13:55:16 2013
@@ -0,0 +1,156 @@
+/*
+ * prefix-string-test.c: a collection of svn_prefix_string__* tests
+ *
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ */
+
+/* ====================================================================
+ To add tests, look toward the bottom of this file.
+
+*/
+
+
+
+#include <stdio.h>
+#include <string.h>
+#include <apr_pools.h>
+
+#include "../svn_test.h"
+
+#include "svn_error.h"
+#include "svn_string.h" /* This includes <apr_*.h> */
+#include "private/svn_string_private.h"
+
+/* Some of our own global variables, for simplicity. Yes,
+ simplicity. */
+svn_stringbuf_t *a = NULL, *b = NULL, *c = NULL;
+const char *phrase_1 = "hello, ";
+const char *phrase_2 = "a longish phrase of sorts, longer than 16 anyway";
+
+
+static svn_error_t *
+test_empty_string(apr_pool_t *pool)
+{
+ svn_prefix_tree__t *tree = svn_prefix_tree__create(pool);
+ svn_prefix_string__t *empty = svn_prefix_string__create(tree, "");
+
+ /* same instance for all strings of the same value */
+ SVN_TEST_ASSERT(empty == svn_prefix_string__create(tree, ""));
+
+ /* does it actually have the right contents? */
+ SVN_TEST_ASSERT(svn_prefix_string__expand(empty, pool)->len == 0);
+ SVN_TEST_STRING_ASSERT(svn_prefix_string__expand(empty, pool)->data, "");
+
+ /* strings shall be equal to themselves */
+ SVN_TEST_ASSERT(0 == svn_prefix_string__compare(empty, empty));
+
+ return SVN_NO_ERROR;
+}
+
+enum {TEST_CASE_COUNT = 9};
+
+const char *test_cases[TEST_CASE_COUNT] =
+{
+ "a longish string of sorts, longer than 7 anyway",
+ "some other string",
+ "more stuff on root",
+ "some shorter string",
+ "some short string",
+ "some short str",
+ "some short str2",
+ "a longish string of sorts, longer than ?! anyway",
+ "a"
+};
+
+static svn_error_t *
+test_string_creation(apr_pool_t *pool)
+{
+ svn_prefix_tree__t *tree = svn_prefix_tree__create(pool);
+ svn_prefix_string__t *strings[TEST_CASE_COUNT];
+ int i;
+
+ /* create strings and remember their initial references */
+ for (i = 0; i < TEST_CASE_COUNT; ++i)
+ strings[i] = svn_prefix_string__create(tree, test_cases[i]);
+
+ /* doing this again must yield the same pointers */
+ for (i = 0; i < TEST_CASE_COUNT; ++i)
+ SVN_TEST_ASSERT(strings[i]
+ == svn_prefix_string__create(tree, test_cases[i]));
+
+ /* converting them back to strings must be the initial values */
+ for (i = 0; i < TEST_CASE_COUNT; ++i)
+ {
+ svn_string_t *expanded = svn_prefix_string__expand(strings[i], pool);
+
+ SVN_TEST_ASSERT(expanded->len == strlen(test_cases[i]));
+ SVN_TEST_STRING_ASSERT(expanded->data, test_cases[i]);
+
+ }
+
+ return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+test_string_comparison(apr_pool_t *pool)
+{
+ svn_prefix_tree__t *tree = svn_prefix_tree__create(pool);
+ svn_prefix_string__t *strings[TEST_CASE_COUNT];
+ int i, k;
+
+ /* create strings */
+ for (i = 0; i < TEST_CASE_COUNT; ++i)
+ strings[i] = svn_prefix_string__create(tree, test_cases[i]);
+
+ /* comparing them with themselves */
+ for (i = 0; i < TEST_CASE_COUNT; ++i)
+ SVN_TEST_ASSERT(! svn_prefix_string__compare(strings[i], strings[i]));
+
+ /* compare with all other strings */
+ for (i = 0; i < TEST_CASE_COUNT; ++i)
+ {
+ svn_string_t *lhs = svn_prefix_string__expand(strings[i], pool);
+ for (k = 0; k < TEST_CASE_COUNT; ++k)
+ {
+ svn_string_t *rhs = svn_prefix_string__expand(strings[k], pool);
+ int expected_diff = strcmp(lhs->data, rhs->data);
+ int actual_diff = svn_prefix_string__compare(strings[i], strings[k]);
+
+ SVN_TEST_ASSERT((actual_diff < 0) == (expected_diff < 0));
+ SVN_TEST_ASSERT((actual_diff > 0) == (expected_diff > 0));
+ SVN_TEST_ASSERT(!actual_diff == !expected_diff);
+ }
+ }
+
+ return SVN_NO_ERROR;
+}
+
+/* An array of all test functions */
+struct svn_test_descriptor_t test_funcs[] =
+ {
+ SVN_TEST_NULL,
+ SVN_TEST_PASS2(test_empty_string,
+ "check empty strings"),
+ SVN_TEST_PASS2(test_string_creation,
+ "create many strings"),
+ SVN_TEST_PASS2(test_string_comparison,
+ "compare strings"),
+ SVN_TEST_NULL
+ };