summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorYann Ylavic <ylavic@apache.org>2022-06-27 18:39:02 +0000
committerYann Ylavic <ylavic@apache.org>2022-06-27 18:39:02 +0000
commit583c6bdd3d8cb8fbc721e28f0d96080c05d32628 (patch)
tree11ce4f7b48c0c0ea1cbb3b282ba7829f622210ed /test
parentc01b709f642aae24af11070bd648bd7dc9686db8 (diff)
downloadapr-583c6bdd3d8cb8fbc721e28f0d96080c05d32628.tar.gz
testencode: Follow up to r1902281: Inline, no calling convention assumptions.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1902286 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r--test/testencode.c118
1 files changed, 64 insertions, 54 deletions
diff --git a/test/testencode.c b/test/testencode.c
index 2f7371666..ca9ddb372 100644
--- a/test/testencode.c
+++ b/test/testencode.c
@@ -905,47 +905,52 @@ static void test_decode_base16_binary(abts_case * tc, void *data)
apr_pool_destroy(pool);
}
-#ifdef WIN32
-typedef apr_status_t (__stdcall *encdec_fn)(char*, const char*, apr_ssize_t, int, apr_size_t*);
-#else
-typedef apr_status_t (*encdec_fn)(char*, const char*, apr_ssize_t, int, apr_size_t*);
-#endif
-
static void test_encode_errors(abts_case * tc, void *data)
{
char dest[64];
apr_size_t len;
apr_status_t rv;
- const encdec_fn *enc, encs[] = {
- (encdec_fn)apr_encode_base64,
- (encdec_fn)apr_encode_base64_binary,
- (encdec_fn)apr_encode_base32,
- (encdec_fn)apr_encode_base32_binary,
- (encdec_fn)apr_encode_base16,
- (encdec_fn)apr_encode_base16_binary,
- NULL
- };
- for (enc = encs; *enc; ++enc) {
- rv = (*enc)(dest, "", -2, 0, &len);
- ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
-
- rv = (*enc)(dest, NULL, APR_ENCODE_STRING, 0, &len);
- ABTS_INT_EQUAL(tc, APR_NOTFOUND, rv);
-
-#if 0
- /* Can't test APR_ENOSPC without a NUL terminated buffer of
- * length APR_SIZE_MAX / 4 * 3 and passing APR_ENCODE_STRING,
- * which we won't even think about :)
- */
- {
- static char huge_buffer[APR_SIZE_MAX / 4 * 3 + 1];
- memset(huge_buffer, !0, sizeof(huge_buffer) - 1);
- rv = (*enc)(NULL, huge_buffer, APR_ENCODE_STRING, &len);
- ABTS_INT_EQUAL(tc, APR_ENOSPC, rv);
- }
-#endif
- }
+ /* Can't test APR_ENOSPC without a NUL terminated buffer of
+ * length APR_SIZE_MAX / 4 * 3 and passing APR_ENCODE_STRING,
+ * which we won't even think about :)
+ */
+
+ /* base64 */
+ rv = apr_encode_base64(dest, "", -2, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
+ rv = apr_encode_base64(dest, NULL, APR_ENCODE_STRING, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_NOTFOUND, rv);
+
+ /* base64_binary */
+ rv = apr_encode_base64_binary(dest, (const unsigned char *)"", -2, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
+ rv = apr_encode_base64_binary(dest, NULL, APR_ENCODE_STRING, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_NOTFOUND, rv);
+
+ /* base32 */
+ rv = apr_encode_base32(dest, "", -2, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
+ rv = apr_encode_base32(dest, NULL, APR_ENCODE_STRING, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_NOTFOUND, rv);
+
+ /* base32_binary */
+ rv = apr_encode_base32_binary(dest, (const unsigned char *)"", -2, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
+ rv = apr_encode_base32_binary(dest, NULL, APR_ENCODE_STRING, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_NOTFOUND, rv);
+
+ /* base16 */
+ rv = apr_encode_base16(dest, "", -2, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
+ rv = apr_encode_base16(dest, NULL, APR_ENCODE_STRING, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_NOTFOUND, rv);
+
+ /* base16_binary */
+ rv = apr_encode_base16_binary(dest, (const unsigned char *)"", -2, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
+ rv = apr_encode_base16_binary(dest, NULL, APR_ENCODE_STRING, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_NOTFOUND, rv);
}
static void test_decode_errors(abts_case * tc, void *data)
@@ -955,26 +960,11 @@ static void test_decode_errors(abts_case * tc, void *data)
apr_status_t rv;
unsigned char *udest = (unsigned char *)dest;
- const encdec_fn *dec, decs[] = {
- (encdec_fn)apr_decode_base64,
- (encdec_fn)apr_decode_base64_binary,
- (encdec_fn)apr_decode_base32,
- (encdec_fn)apr_decode_base32_binary,
- (encdec_fn)apr_decode_base16,
- (encdec_fn)apr_decode_base16_binary,
- NULL
- };
- for (dec = decs; *dec; ++dec) {
- rv = (*dec)(dest, "", -2, 0, &len);
- ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
-
- rv = (*dec)(dest, NULL, APR_ENCODE_STRING, 0, &len);
- ABTS_INT_EQUAL(tc, APR_NOTFOUND, rv);
-
- /* No possible APR_ENOSPC when decoding */
- }
-
/* base64 */
+ rv = apr_decode_base64(dest, "", -2, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
+ rv = apr_decode_base64(dest, NULL, APR_ENCODE_STRING, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_NOTFOUND, rv);
rv = apr_decode_base64(NULL, NULL, 5, 0, &len);
ABTS_INT_EQUAL(tc, APR_EINCOMPLETE, rv);
rv = apr_decode_base64(dest, "ABCDE", APR_ENCODE_STRING, 0, &len);
@@ -987,6 +977,10 @@ static void test_decode_errors(abts_case * tc, void *data)
ABTS_SIZE_EQUAL(tc, 3, len);
/* base64_binary */
+ rv = apr_decode_base64_binary(udest, "", -2, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
+ rv = apr_decode_base64_binary(udest, NULL, APR_ENCODE_STRING, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_NOTFOUND, rv);
rv = apr_decode_base64_binary(NULL, NULL, 5, 0, &len);
ABTS_INT_EQUAL(tc, APR_EINCOMPLETE, rv);
rv = apr_decode_base64_binary(udest, "ABCDE", APR_ENCODE_STRING, 0, &len);
@@ -999,6 +993,10 @@ static void test_decode_errors(abts_case * tc, void *data)
ABTS_SIZE_EQUAL(tc, 3, len);
/* base32 */
+ rv = apr_decode_base32(dest, "", -2, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
+ rv = apr_decode_base32(dest, NULL, APR_ENCODE_STRING, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_NOTFOUND, rv);
rv = apr_decode_base32(NULL, NULL, 9, 0, &len);
ABTS_INT_EQUAL(tc, APR_EINCOMPLETE, rv);
rv = apr_decode_base32(NULL, NULL, 11, 0, &len);
@@ -1019,6 +1017,10 @@ static void test_decode_errors(abts_case * tc, void *data)
ABTS_SIZE_EQUAL(tc, 5, len);
/* base32_binary */
+ rv = apr_decode_base32_binary(udest, "", -2, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
+ rv = apr_decode_base32_binary(udest, NULL, APR_ENCODE_STRING, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_NOTFOUND, rv);
rv = apr_decode_base32_binary(NULL, NULL, 9, 0, &len);
ABTS_INT_EQUAL(tc, APR_EINCOMPLETE, rv);
rv = apr_decode_base32_binary(NULL, NULL, 11, 0, &len);
@@ -1039,6 +1041,10 @@ static void test_decode_errors(abts_case * tc, void *data)
ABTS_SIZE_EQUAL(tc, 5, len);
/* base16 */
+ rv = apr_decode_base16(dest, "", -2, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
+ rv = apr_decode_base16(dest, NULL, APR_ENCODE_STRING, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_NOTFOUND, rv);
rv = apr_decode_base16(NULL, NULL, 3, 0, &len);
ABTS_INT_EQUAL(tc, APR_EINCOMPLETE, rv);
rv = apr_decode_base16(dest, "ABC", APR_ENCODE_STRING, 0, &len);
@@ -1065,6 +1071,10 @@ static void test_decode_errors(abts_case * tc, void *data)
ABTS_SIZE_EQUAL(tc, 2, len);
/* base16_binary */
+ rv = apr_decode_base16_binary(udest, "", -2, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
+ rv = apr_decode_base16_binary(udest, NULL, APR_ENCODE_STRING, 0, &len);
+ ABTS_INT_EQUAL(tc, APR_NOTFOUND, rv);
rv = apr_decode_base16_binary(NULL, NULL, 3, 0, &len);
ABTS_INT_EQUAL(tc, APR_EINCOMPLETE, rv);
rv = apr_decode_base16_binary(udest, "ABC", APR_ENCODE_STRING, 0, &len);