Author: ivan
Date: Wed Nov  4 09:59:54 2026
New Revision: 1940014

Log:
Add tests for current behavior of svn_cstring_strtoui64().

* subversion/tests/svn_test.h
  (SVN_TEST_ASSERT_ERROR_MSG): New. Same as SVN_TEST_ASSERT_ERROR but also
   tests error message.

* subversion/tests/libsvn_subr/string-test.c
  (test_svn_cstring_strtoui64): New test.
  (test_funcs): Add test_svn_cstring_strtoui64.

Modified:
   subversion/trunk/subversion/tests/libsvn_subr/string-test.c
   subversion/trunk/subversion/tests/svn_test.h

Modified: subversion/trunk/subversion/tests/libsvn_subr/string-test.c
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/string-test.c Wed Nov  4 
08:49:13 2026        (r1940013)
+++ subversion/trunk/subversion/tests/libsvn_subr/string-test.c Wed Nov  4 
09:59:54 2026        (r1940014)
@@ -1067,6 +1067,55 @@ test_cstring_join(apr_pool_t *pool)
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+test_svn_cstring_strtoui64(apr_pool_t *pool)
+{
+  apr_uint64_t actual;
+
+  SVN_ERR(svn_cstring_strtoui64(&actual, "0", 0, 100, 10));
+
+  SVN_TEST_ASSERT_ERROR_MSG(
+    svn_cstring_strtoui64(&actual, "101", 0, 100, 10),
+    SVN_ERR_INCORRECT_PARAMS,
+    "Number '101' is out of range '[0, 100]'");
+
+  /* 9223372036854775807 is APR_INT64_MAX */
+  SVN_ERR(svn_cstring_strtoui64(&actual, "9223372036854775807",
+                                0, APR_UINT64_MAX, 10));
+
+  /* 9223372036854775808 is APR_INT64_MAX + 1 */
+  /* ## The error message should be improved. */
+  SVN_TEST_ASSERT_ERROR_MSG(
+    svn_cstring_strtoui64(&actual, "9223372036854775808", 0,
+                          APR_UINT64_MAX, 10),
+    SVN_ERR_INCORRECT_PARAMS,
+    "Number '9223372036854775808' is out of range '[0, 
18446744073709551615]'");
+
+  /* 18446744073709551615 is APR_UINT64_MAX */
+  /* ## The error message should be improved.  */
+  SVN_TEST_ASSERT_ERROR_MSG(
+    svn_cstring_strtoui64(&actual, "18446744073709551615", 0,
+                          APR_UINT64_MAX, 10),
+    SVN_ERR_INCORRECT_PARAMS,
+    "Number '18446744073709551615' is out of range '[0, 
18446744073709551615]'");
+
+  /* 18446744073709551615 is APR_UINT64_MAX */
+  /* ## The error message should be improved. */
+  SVN_TEST_ASSERT_ERROR_MSG(svn_cstring_strtoui64(&actual,
+                                                  "18446744073709551615", 0,
+                                                  APR_UINT64_MAX, 10),
+                            SVN_ERR_INCORRECT_PARAMS,
+                            "Number '18446744073709551615' is out of range "
+                            "'[0, 18446744073709551615]'");
+
+  SVN_TEST_ASSERT_ERROR_MSG(
+    svn_cstring_strtoui64(&actual, "-1", 0, APR_UINT64_MAX, 10),
+    SVN_ERR_INCORRECT_PARAMS,
+    "Number '-1' is out of range '[0, 18446744073709551615]'");
+
+  return SVN_NO_ERROR;
+}
+
 /*
    ====================================================================
    If you add a new test to this file, update this array.
@@ -1151,6 +1200,8 @@ static struct svn_test_descriptor_t test
                    "test svn_stringbuf_set()"),
     SVN_TEST_PASS2(test_cstring_join,
                    "test svn_cstring_join2()"),
+    SVN_TEST_PASS2(test_svn_cstring_strtoui64,
+                   "test svn_cstring_strtoui64()"),
     SVN_TEST_NULL
   };
 

Modified: subversion/trunk/subversion/tests/svn_test.h
==============================================================================
--- subversion/trunk/subversion/tests/svn_test.h        Wed Nov  4 08:49:13 
2026        (r1940013)
+++ subversion/trunk/subversion/tests/svn_test.h        Wed Nov  4 09:59:54 
2026        (r1940014)
@@ -191,6 +191,27 @@ extern "C" {
       }                                                           \
   } while(0)
 
+/** Same SVN_TEST_ASSERT_ERROR but also tests expected message
+ */
+#define SVN_TEST_ASSERT_ERROR_MSG(expr, expected_err, expected_msg)           \
+  do                                                                          \
+    {                                                                         \
+      svn_error_t *err__ = (expr);                                            \
+      SVN_ERR_ASSERT((expected_err));                                         \
+      if (err__ == SVN_NO_ERROR || err__->apr_err != (expected_err))          \
+        return err__ ? svn_error_createf(                                     \
+                           SVN_ERR_TEST_FAILED, err__,                        \
+                           "Expected error %s but got %s",                    \
+                           svn_error_symbolic_name(expected_err),             \
+                           svn_error_symbolic_name(err__->apr_err))           \
+                     : svn_error_createf(SVN_ERR_TEST_FAILED, err__,          \
+                                         "Expected error %s but got %s",      \
+                                         
svn_error_symbolic_name(expected_err), \
+                                         "SVN_NO_ERROR");                     \
+  SVN_TEST_STRING_ASSERT(err__->message, expected_msg);                       \
+  svn_error_clear(err__);                                                     \
+}                                                                             \
+while (0)
 
 /* Baton for any arguments that need to be passed from main() to svn
  * test functions.

Reply via email to