svn commit: r1935444 - apr/apr/trunk/test

[email protected] Tue, 16 Jun 2026 23:16:11 -0000
Newsgroups gmane.comp.apache.apr.cvs
Message-ID <178165177181.2577163.11387742815710553916@svn03-he-fi>
Author: brane
Date: Tue Jun 16 23:16:11 2026
New Revision: 1935444

Log:
Add an optional context to the test driver's assertions.

 * test/abts: Add context to all assertion functions, add new assertion
              helper macros with a context parameter.
 * test/testxml.c: Adjust the direct call to abts_str_equal.
 * test/testxlate.c: Add the conversion context to the expected result check.

Modified:
   apr/apr/trunk/test/abts.c
   apr/apr/trunk/test/abts.h
   apr/apr/trunk/test/testxlate.c
   apr/apr/trunk/test/testxml.c

Modified: apr/apr/trunk/test/abts.c
==============================================================================
--- apr/apr/trunk/test/abts.c	Tue Jun 16 20:45:56 2026	(r1935443)
+++ apr/apr/trunk/test/abts.c	Tue Jun 16 23:16:11 2026	(r1935444)
@@ -282,7 +282,7 @@ void abts_log_message(const char *fmt, .
 }
 
 #define IMPL_abts_T_equal(T, NAME, FMT, CAST) \
-void abts_##NAME##_equal(abts_case *tc, const T expected, const T actual, int lineno) \
+void abts_##NAME##_equal(const char *ctx, abts_case *tc, const T expected, const T actual, int lineno) \
 { \
     update_status(); \
     if (tc->failed) return; \
@@ -291,8 +291,12 @@ void abts_##NAME##_equal(abts_case *tc,
     \
     tc->failed = TRUE; \
     if (verbose) { \
-        fprintf(stderr, "Line %d: expected <%" FMT ">, but saw <%" FMT ">\n", \
-                lineno, CAST expected, CAST actual); \
+        if (ctx) \
+            fprintf(stderr, "%s: line %d: expected <%" FMT ">, but saw <%" FMT ">\n", \
+                    ctx, lineno, CAST expected, CAST actual);            \
+        else \
+            fprintf(stderr, "Line %d: expected <%" FMT ">, but saw <%" FMT ">\n", \
+                    lineno, CAST expected, CAST actual); \
         fflush(stderr); \
     } \
 }
@@ -305,7 +309,7 @@ IMPL_abts_T_equal(unsigned long long, ul
 IMPL_abts_T_equal(size_t,             size,   "lu",  (unsigned long))
 
 #define IMPL_abts_T_nequal(T, NAME, FMT, CAST) \
-void abts_##NAME##_nequal(abts_case *tc, const T expected, const T actual, int lineno) \
+void abts_##NAME##_nequal(const char *ctx, abts_case *tc, const T expected, const T actual, int lineno) \
 { \
     update_status(); \
     if (tc->failed) return; \
@@ -314,9 +318,14 @@ void abts_##NAME##_nequal(abts_case *tc,
     \
     tc->failed = TRUE; \
     if (verbose) { \
-        fprintf(stderr, "Line %d: expected something other than <%" FMT ">, " \
-                "but saw <%" FMT ">\n", \
-                lineno, CAST expected, CAST actual); \
+        if (ctx) \
+            fprintf(stderr, "%s: line %d: expected something other than <%" FMT ">, " \
+                    "but saw <%" FMT ">\n", \
+                    ctx, lineno, CAST expected, CAST actual); \
+        else \
+            fprintf(stderr, "Line %d: expected something other than <%" FMT ">, " \
+                    "but saw <%" FMT ">\n", \
+                    lineno, CAST expected, CAST actual); \
         fflush(stderr); \
     } \
 }
@@ -328,7 +337,7 @@ IMPL_abts_T_nequal(long long,          l
 IMPL_abts_T_nequal(unsigned long long, ullong, "llu", (unsigned long long))
 IMPL_abts_T_nequal(size_t,             size,   "lu",  (unsigned long))
 
-void abts_str_equal(abts_case *tc, const char *expected, const char *actual, int lineno)
+void abts_str_equal(const char *ctx, abts_case *tc, const char *expected, const char *actual, int lineno)
 {
     update_status();
     if (tc->failed) return;
@@ -339,12 +348,15 @@ void abts_str_equal(abts_case *tc, const
 
     tc->failed = TRUE;
     if (verbose) {
-        fprintf(stderr, "Line %d: expected <%s>, but saw <%s>\n", lineno, expected, actual);
+        if (ctx)
+            fprintf(stderr, "%s: line %d: expected <%s>, but saw <%s>\n", ctx, lineno, expected, actual);
+        else
+            fprintf(stderr, "Line %d: expected <%s>, but saw <%s>\n", lineno, expected, actual);
         fflush(stderr);
     }
 }
 
-void abts_str_nequal(abts_case *tc, const char *expected, const char *actual,
+void abts_str_nequal(const char *ctx, abts_case *tc, const char *expected, const char *actual,
                        size_t n, int lineno)
 {
     update_status();
@@ -354,13 +366,17 @@ void abts_str_nequal(abts_case *tc, cons
 
     tc->failed = TRUE;
     if (verbose) {
-        fprintf(stderr, "Line %d: expected something other than <%s>, but saw <%s>\n",
-                lineno, expected, actual);
+        if (ctx)
+            fprintf(stderr, "%s: line %d: expected something other than <%s>, but saw <%s>\n",
+                    ctx, lineno, expected, actual);
+        else
+            fprintf(stderr, "Line %d: expected something other than <%s>, but saw <%s>\n",
+                    lineno, expected, actual);
         fflush(stderr);
     }
 }
 
-void abts_ptr_notnull(abts_case *tc, const void *ptr, int lineno)
+void abts_ptr_notnull(const char *ctx, abts_case *tc, const void *ptr, int lineno)
 {
     update_status();
     if (tc->failed) return;
@@ -369,12 +385,15 @@ void abts_ptr_notnull(abts_case *tc, con
 
     tc->failed = TRUE;
     if (verbose) {
-        fprintf(stderr, "Line %d: expected non-NULL, but saw NULL\n", lineno);
+        if (ctx)
+            fprintf(stderr, "%s: line %d: expected non-NULL, but saw NULL\n", ctx, lineno);
+        else
+            fprintf(stderr, "Line %d: expected non-NULL, but saw NULL\n", lineno);
         fflush(stderr);
     }
 }
 
-void abts_ptr_equal(abts_case *tc, const void *expected, const void *actual, int lineno)
+void abts_ptr_equal(const char *ctx, abts_case *tc, const void *expected, const void *actual, int lineno)
 {
     update_status();
     if (tc->failed) return;
@@ -383,7 +402,10 @@ void abts_ptr_equal(abts_case *tc, const
 
     tc->failed = TRUE;
     if (verbose) {
-        fprintf(stderr, "Line %d: expected <%p>, but saw <%p>\n", lineno, expected, actual);
+        if (ctx)
+            fprintf(stderr, "%s: line %d: expected <%p>, but saw <%p>\n", ctx, lineno, expected, actual);
+        else
+            fprintf(stderr, "Line %d: expected <%p>, but saw <%p>\n", lineno, expected, actual);
         fflush(stderr);
     }
 }
@@ -426,7 +448,7 @@ void abts_assert(abts_case *tc, const ch
     }
 }
 
-void abts_true(abts_case *tc, int condition, int lineno)
+void abts_true(const char *ctx, abts_case *tc, int condition, int lineno)
 {
     update_status();
     if (tc->failed) return;
@@ -435,7 +457,10 @@ void abts_true(abts_case *tc, int condit
 
     tc->failed = TRUE;
     if (verbose) {
-        fprintf(stderr, "Line %d: Condition is false, but expected true\n", lineno);
+        if (ctx)
+            fprintf(stderr, "%s: line %d: Condition is false, but expected true\n", ctx, lineno);
+        else
+            fprintf(stderr, "Line %d: Condition is false, but expected true\n", lineno);
         fflush(stderr);
     }
 }
@@ -503,4 +528,3 @@ int main(int argc, const char *const arg
     abts_free_suite(suite);
     return rv;
 }
-

Modified: apr/apr/trunk/test/abts.h
==============================================================================
--- apr/apr/trunk/test/abts.h	Tue Jun 16 20:45:56 2026	(r1935443)
+++ apr/apr/trunk/test/abts.h	Tue Jun 16 23:16:11 2026	(r1935444)
@@ -70,64 +70,85 @@ abts_suite *abts_add_suite(abts_suite *s
 void abts_run_test(abts_suite *ts, test_func f, void *value);
 void abts_log_message(const char *fmt, ...);
 
-void abts_int_equal(abts_case *tc, const int expected, const int actual, int lineno);
-void abts_int_nequal(abts_case *tc, const int expected, const int actual, int lineno);
-void abts_uint_equal(abts_case *tc, const unsigned int expected,
+void abts_int_equal(const char *ctx, abts_case *tc, const int expected, const int actual, int lineno);
+void abts_int_nequal(const char *ctx, abts_case *tc, const int expected, const int actual, int lineno);
+void abts_uint_equal(const char *ctx, abts_case *tc, const unsigned int expected,
                      const unsigned int actual, int lineno);
-void abts_uint_nequal(abts_case *tc, const unsigned int expected,
+void abts_uint_nequal(const char *ctx, abts_case *tc, const unsigned int expected,
                       const unsigned int actual, int lineno);
-void abts_long_equal(abts_case *tc, const long expected,
+void abts_long_equal(const char *ctx, abts_case *tc, const long expected,
                      const long actual, int lineno);
-void abts_long_nequal(abts_case *tc, const long expected,
+void abts_long_nequal(const char *ctx, abts_case *tc, const long expected,
                       const long actual, int lineno);
-void abts_ulong_equal(abts_case *tc, const unsigned long expected,
+void abts_ulong_equal(const char *ctx, abts_case *tc, const unsigned long expected,
                       const unsigned long actual, int lineno);
-void abts_ulong_nequal(abts_case *tc, const unsigned long expected,
+void abts_ulong_nequal(const char *ctx, abts_case *tc, const unsigned long expected,
                        const unsigned long actual, int lineno);
-void abts_llong_equal(abts_case *tc, const long long expected,
+void abts_llong_equal(const char *ctx, abts_case *tc, const long long expected,
                       const long long actual, int lineno);
-void abts_llong_nequal(abts_case *tc, const long long expected,
+void abts_llong_nequal(const char *ctx, abts_case *tc, const long long expected,
                        const long long actual, int lineno);
-void abts_ullong_equal(abts_case *tc, const unsigned long long expected,
+void abts_ullong_equal(const char *ctx, abts_case *tc, const unsigned long long expected,
                        const unsigned long long actual, int lineno);
-void abts_ullong_nequal(abts_case *tc, const unsigned long long expected,
+void abts_ullong_nequal(const char *ctx, abts_case *tc, const unsigned long long expected,
                         const unsigned long long actual, int lineno);
-void abts_size_equal(abts_case *tc, size_t expected, size_t actual, int lineno);
-void abts_size_nequal(abts_case *tc, size_t expected, size_t actual, int lineno);
-void abts_str_equal(abts_case *tc, const char *expected, const char *actual, int lineno);
-void abts_str_nequal(abts_case *tc, const char *expected, const char *actual,
+void abts_size_equal(const char *ctx, abts_case *tc, size_t expected, size_t actual, int lineno);
+void abts_size_nequal(const char *ctx, abts_case *tc, size_t expected, size_t actual, int lineno);
+void abts_str_equal(const char *ctx, abts_case *tc, const char *expected, const char *actual, int lineno);
+void abts_str_nequal(const char *ctx, abts_case *tc, const char *expected, const char *actual,
                        size_t n, int lineno);
-void abts_ptr_notnull(abts_case *tc, const void *ptr, int lineno);
-void abts_ptr_equal(abts_case *tc, const void *expected, const void *actual, int lineno);
-void abts_true(abts_case *tc, int condition, int lineno);
+void abts_ptr_notnull(const char *ctx, abts_case *tc, const void *ptr, int lineno);
+void abts_ptr_equal(const char *ctx, abts_case *tc, const void *expected, const void *actual, int lineno);
+void abts_true(const char *ctx, abts_case *tc, int condition, int lineno);
 void abts_fail(abts_case *tc, const char *message, int lineno);
 void abts_skip(abts_case *tc, const char *message, int lineno);
 void abts_not_impl(abts_case *tc, const char *message, int lineno);
 void abts_assert(abts_case *tc, const char *message, int condition, int lineno);
 
 /* Convenience macros. Ryan hates these! */
-#define ABTS_INT_EQUAL(a, b, c)     abts_int_equal(a, b, c, __LINE__)
-#define ABTS_INT_NEQUAL(a, b, c)    abts_int_nequal(a, b, c, __LINE__)
-#define ABTS_UINT_EQUAL(a, b, c)    abts_uint_equal(a, b, c, __LINE__)
-#define ABTS_UINT_NEQUAL(a, b, c)   abts_uint_nequal(a, b, c, __LINE__)
-#define ABTS_LONG_EQUAL(a, b, c)    abts_long_equal(a, b, c, __LINE__)
-#define ABTS_LONG_NEQUAL(a, b, c)   abts_long_nequal(a, b, c, __LINE__)
-#define ABTS_ULONG_EQUAL(a, b, c)   abts_ulong_equal(a, b, c, __LINE__)
-#define ABTS_ULONG_NEQUAL(a, b, c)  abts_ulong_nequal(a, b, c, __LINE__)
-#define ABTS_LLONG_EQUAL(a, b, c)   abts_llong_equal(a, b, c, __LINE__)
-#define ABTS_LLONG_NEQUAL(a, b, c)  abts_llong_nequal(a, b, c, __LINE__)
-#define ABTS_ULLONG_EQUAL(a, b, c)  abts_ullong_equal(a, b, c, __LINE__)
-#define ABTS_ULLONG_NEQUAL(a, b, c) abts_ullong_nequal(a, b, c, __LINE__)
-#define ABTS_SIZE_EQUAL(a, b, c)    abts_size_equal(a, b, c, __LINE__)
-#define ABTS_SIZE_NEQUAL(a, b, c)   abts_size_nequal(a, b, c, __LINE__)
-#define ABTS_STR_EQUAL(a, b, c)     abts_str_equal(a, b, c, __LINE__)
-#define ABTS_STR_NEQUAL(a, b, c, d) abts_str_nequal(a, b, c, d, __LINE__)
-#define ABTS_PTR_NOTNULL(a, b)      abts_ptr_notnull(a, b, __LINE__)
-#define ABTS_PTR_EQUAL(a, b, c)     abts_ptr_equal(a, b, c, __LINE__)
-#define ABTS_TRUE(a, b)             abts_true(a, b, __LINE__);
-#define ABTS_FAIL(a, b)             abts_fail(a, b, __LINE__);
-#define ABTS_NOT_IMPL(a, b)         abts_not_impl(a, b, __LINE__);
-#define ABTS_ASSERT(a, b, c)        abts_assert(a, b, c, __LINE__);
+#define ABTS_INT_EQUAL(a, b, c)     abts_int_equal(NULL, (a), (b), (c), __LINE__)
+#define ABTS_INT_NEQUAL(a, b, c)    abts_int_nequal(NULL, (a), (b), (c), __LINE__)
+#define ABTS_UINT_EQUAL(a, b, c)    abts_uint_equal(NULL, (a), (b), (c), __LINE__)
+#define ABTS_UINT_NEQUAL(a, b, c)   abts_uint_nequal(NULL, (a), (b), (c), __LINE__)
+#define ABTS_LONG_EQUAL(a, b, c)    abts_long_equal(NULL, (a), (b), (c), __LINE__)
+#define ABTS_LONG_NEQUAL(a, b, c)   abts_long_nequal(NULL, (a), (b), (c), __LINE__)
+#define ABTS_ULONG_EQUAL(a, b, c)   abts_ulong_equal(NULL, (a), (b), (c), __LINE__)
+#define ABTS_ULONG_NEQUAL(a, b, c)  abts_ulong_nequal(NULL, (a), (b), (c), __LINE__)
+#define ABTS_LLONG_EQUAL(a, b, c)   abts_llong_equal(NULL, (a), (b), (c), __LINE__)
+#define ABTS_LLONG_NEQUAL(a, b, c)  abts_llong_nequal(NULL, (a), (b), (c), __LINE__)
+#define ABTS_ULLONG_EQUAL(a, b, c)  abts_ullong_equal(NULL, (a), (b), (c), __LINE__)
+#define ABTS_ULLONG_NEQUAL(a, b, c) abts_ullong_nequal(NULL, (a), (b), (c), __LINE__)
+#define ABTS_SIZE_EQUAL(a, b, c)    abts_size_equal(NULL, (a), (b), (c), __LINE__)
+#define ABTS_SIZE_NEQUAL(a, b, c)   abts_size_nequal(NULL, (a), (b), (c), __LINE__)
+#define ABTS_STR_EQUAL(a, b, c)     abts_str_equal(NULL, (a), (b), (c), __LINE__)
+#define ABTS_STR_NEQUAL(a, b, c, d) abts_str_nequal(NULL, (a), (b), (c), (d), __LINE__)
+#define ABTS_PTR_NOTNULL(a, b)      abts_ptr_notnull(NULL, (a), (b), __LINE__)
+#define ABTS_PTR_EQUAL(a, b, c)     abts_ptr_equal(NULL, (a), (b), (c), __LINE__)
+#define ABTS_TRUE(a, b)             abts_true(NULL, (a), (b), __LINE__);
+
+#define ABTS_CTX_INT_EQUAL(x, a, b, c)     abts_int_equal((x), (a), (b), (c), __LINE__)
+#define ABTS_CTX_INT_NEQUAL(x, a, b, c)    abts_int_nequal((x), (a), (b), (c), __LINE__)
+#define ABTS_CTX_UINT_EQUAL(x, a, b, c)    abts_uint_equal((x), (a), (b), (c), __LINE__)
+#define ABTS_CTX_UINT_NEQUAL(x, a, b, c)   abts_uint_nequal((x), (a), (b), (c), __LINE__)
+#define ABTS_CTX_LONG_EQUAL(x, a, b, c)    abts_long_equal((x), (a), (b), (c), __LINE__)
+#define ABTS_CTX_LONG_NEQUAL(x, a, b, c)   abts_long_nequal((x), (a), (b), (c), __LINE__)
+#define ABTS_CTX_ULONG_EQUAL(x, a, b, c)   abts_ulong_equal((x), (a), (b), (c), __LINE__)
+#define ABTS_CTX_ULONG_NEQUAL(x, a, b, c)  abts_ulong_nequal((x), (a), (b), (c), __LINE__)
+#define ABTS_CTX_LLONG_EQUAL(x, a, b, c)   abts_llong_equal((x), (a), (b), (c), __LINE__)
+#define ABTS_CTX_LLONG_NEQUAL(x, a, b, c)  abts_llong_nequal((x), (a), (b), (c), __LINE__)
+#define ABTS_CTX_ULLONG_EQUAL(x, a, b, c)  abts_ullong_equal((x), (a), (b), (c), __LINE__)
+#define ABTS_CTX_ULLONG_NEQUAL(x, a, b, c) abts_ullong_nequal((x), (a), (b), (c), __LINE__)
+#define ABTS_CTX_SIZE_EQUAL(x, a, b, c)    abts_size_equal((x), (a), (b), (c), __LINE__)
+#define ABTS_CTX_SIZE_NEQUAL(x, a, b, c)   abts_size_nequal((x), (a), (b), (c), __LINE__)
+#define ABTS_CTX_STR_EQUAL(x, a, b, c)     abts_str_equal((x), (a), (b), (c), __LINE__)
+#define ABTS_CTX_STR_NEQUAL(x, a, b, c, d) abts_str_nequal((x), (a), (b), (c), (d), __LINE__)
+#define ABTS_CTX_PTR_NOTNULL(x, a, b)      abts_ptr_notnull((x), (a), (b), __LINE__)
+#define ABTS_CTX_PTR_EQUAL(x, a, b, c)     abts_ptr_equal((x), (a), (b), (c), __LINE__)
+#define ABTS_CTX_TRUE(x, a, b)             abts_true((x), (a), (b), __LINE__);
+
+#define ABTS_FAIL(a, b)             abts_fail((a), (b), __LINE__);
+#define ABTS_NOT_IMPL(a, b)         abts_not_impl((a), (b), __LINE__);
+#define ABTS_ASSERT(a, b, c)        abts_assert((a), (b), (c), __LINE__);
 
 /* When skipping tests, make a reference to the test data parameter
    to avoid unused variable warnings. */
@@ -145,4 +166,3 @@ abts_suite *run_tests1(abts_suite *suite
 #ifdef __cplusplus
 }
 #endif
-

Modified: apr/apr/trunk/test/testxlate.c
==============================================================================
--- apr/apr/trunk/test/testxlate.c	Tue Jun 16 20:45:56 2026	(r1935443)
+++ apr/apr/trunk/test/testxlate.c	Tue Jun 16 23:16:11 2026	(r1935444)
@@ -60,9 +60,8 @@ DECLARE_TEST_PARAMS(utf7, utf8, 0);
 #undef DECLARE_TEST_PARAMS
 
 
-static void test_conversion(abts_case *tc, apr_xlate_t *convset,
-                            const char *inbuf, const char *expected,
-                            const char *cs1, const char *cs2, apr_pool_t *pool)
+static void test_conversion(const char *ctx, abts_case *tc, apr_xlate_t *convset,
+                            const char *inbuf, const char *expected)
 {
     static char buf[1024];
     apr_size_t inbytes_left = strlen(inbuf);
@@ -82,16 +81,7 @@ static void test_conversion(abts_case *t
 
     buf[sizeof(buf) - outbytes_left - 1] = '\0';
 
-    {
-        /* Make the source and target encodings part of the comparison
-           so that ABTS prints them if the results don't match, otherwise
-           we wouldn't know which conversion failed. */
-        const char *const expect = apr_psprintf(pool, "%s to %s: %s",
-                                                cs1, cs2, expected);
-        const char *const result = apr_psprintf(pool, "%s to %s: %s",
-                                                cs1, cs2, buf);
-        ABTS_STR_EQUAL(tc, expect, result);
-    }
+    ABTS_CTX_STR_EQUAL(ctx, tc, expected, buf);
 }
 
 /* some iconv implementations don't support all tested transforms;
@@ -135,8 +125,8 @@ static void test_transformation(abts_cas
     if (rv != APR_SUCCESS)
         return;
 
-    test_conversion(tc, convset, params->source, params->expected,
-                    params->cs1, params->cs2, p);
+    test_conversion(apr_psprintf(p, "%s to %s", params->cs1, params->cs2),
+                    tc, convset, params->source, params->expected);
 
     rv = apr_xlate_close(convset);
     ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

Modified: apr/apr/trunk/test/testxml.c
==============================================================================
--- apr/apr/trunk/test/testxml.c	Tue Jun 16 20:45:56 2026	(r1935443)
+++ apr/apr/trunk/test/testxml.c	Tue Jun 16 23:16:11 2026	(r1935444)
@@ -196,7 +196,7 @@ static void roundtrip(abts_case* tc, cha
 
     apr_xml_to_text(pool, doc->root, APR_XML_X2T_FULL_NS_LANG, doc->namespaces, NULL, &actual, NULL);
 
-    abts_str_equal(tc, expected, actual, lineno);
+    abts_str_equal(NULL, tc, expected, actual, lineno);
 
     apr_pool_destroy(pool);
 }