summaryrefslogtreecommitdiffstats
path: root/test/params_api_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/params_api_test.c')
-rw-r--r--test/params_api_test.c89
1 files changed, 73 insertions, 16 deletions
diff --git a/test/params_api_test.c b/test/params_api_test.c
index e47c2643ad..48e2f8920a 100644
--- a/test/params_api_test.c
+++ b/test/params_api_test.c
@@ -455,7 +455,7 @@ static int test_param_real(void)
&& TEST_double_eq(p, 3.14159);
}
-static int test_param_construct(void)
+static int test_param_construct(int tstid)
{
static const char *int_names[] = {
"int", "long", "int32", "int64"
@@ -467,6 +467,10 @@ static int test_param_construct(void)
0xac, 0x75, 0x22, 0x7d, 0x81, 0x06, 0x7a, 0x23,
0xa6, 0xed, 0x87, 0xc7, 0xab, 0xf4, 0x73, 0x22
};
+ OSSL_PARAM *p = NULL, *p1 = NULL;
+ static const OSSL_PARAM params_empty[] = {
+ OSSL_PARAM_END
+ };
OSSL_PARAM params[20];
char buf[100], buf2[100], *bufp, *bufp2;
unsigned char ubuf[100];
@@ -501,13 +505,29 @@ static int test_param_construct(void)
params[n++] = OSSL_PARAM_construct_octet_ptr("octptr", &vp, 0);
params[n] = OSSL_PARAM_construct_end();
+ switch(tstid) {
+ case 0:
+ p = params;
+ break;
+ case 1:
+ p = OSSL_PARAM_merge(params, params_empty);
+ break;
+ case 2:
+ p = OSSL_PARAM_dup(params);
+ break;
+ default:
+ p1 = OSSL_PARAM_dup(params);
+ p = OSSL_PARAM_merge(p1, params_empty);
+ break;
+ }
+
/* Search failure */
- if (!TEST_ptr_null(OSSL_PARAM_locate(params, "fnord")))
+ if (!TEST_ptr_null(OSSL_PARAM_locate(p, "fnord")))
goto err;
/* All signed integral types */
for (j = 0; j < OSSL_NELEM(int_names); j++) {
- if (!TEST_ptr(cp = OSSL_PARAM_locate(params, int_names[j]))
+ if (!TEST_ptr(cp = OSSL_PARAM_locate(p, int_names[j]))
|| !TEST_true(OSSL_PARAM_set_int32(cp, (int32_t)(3 + j)))
|| !TEST_true(OSSL_PARAM_get_int64(cp, &i64))
|| !TEST_size_t_eq(cp->data_size, cp->return_size)
@@ -518,7 +538,7 @@ static int test_param_construct(void)
}
/* All unsigned integral types */
for (j = 0; j < OSSL_NELEM(uint_names); j++) {
- if (!TEST_ptr(cp = OSSL_PARAM_locate(params, uint_names[j]))
+ if (!TEST_ptr(cp = OSSL_PARAM_locate(p, uint_names[j]))
|| !TEST_true(OSSL_PARAM_set_uint32(cp, (uint32_t)(3 + j)))
|| !TEST_true(OSSL_PARAM_get_uint64(cp, &u64))
|| !TEST_size_t_eq(cp->data_size, cp->return_size)
@@ -528,15 +548,16 @@ static int test_param_construct(void)
}
}
/* Real */
- if (!TEST_ptr(cp = OSSL_PARAM_locate(params, "double"))
+ if (!TEST_ptr(cp = OSSL_PARAM_locate(p, "double"))
|| !TEST_true(OSSL_PARAM_set_double(cp, 3.14))
|| !TEST_true(OSSL_PARAM_get_double(cp, &d2))
|| !TEST_size_t_eq(cp->return_size, sizeof(double))
- || !TEST_double_eq(d, d2))
+ || !TEST_double_eq(d2, 3.14)
+ || (tstid <= 1 && !TEST_double_eq(d, d2)))
goto err;
/* UTF8 string */
bufp = NULL;
- if (!TEST_ptr(cp = OSSL_PARAM_locate(params, "utf8str"))
+ if (!TEST_ptr(cp = OSSL_PARAM_locate(p, "utf8str"))
|| !TEST_true(OSSL_PARAM_set_utf8_string(cp, "abcdef"))
|| !TEST_size_t_eq(cp->return_size, sizeof("abcdef") - 1)
|| !TEST_true(OSSL_PARAM_get_utf8_string(cp, &bufp, 0))
@@ -552,15 +573,15 @@ static int test_param_construct(void)
/* UTF8 pointer */
/* Note that the size of a UTF8 string does *NOT* include the NUL byte */
bufp = buf;
- if (!TEST_ptr(cp = OSSL_PARAM_locate(params, "utf8ptr"))
+ if (!TEST_ptr(cp = OSSL_PARAM_locate(p, "utf8ptr"))
|| !TEST_true(OSSL_PARAM_set_utf8_ptr(cp, "tuvwxyz"))
|| !TEST_size_t_eq(cp->return_size, sizeof("tuvwxyz") - 1)
- || !TEST_str_eq(bufp, "tuvwxyz")
|| !TEST_true(OSSL_PARAM_get_utf8_ptr(cp, (const char **)&bufp2))
- || !TEST_ptr_eq(bufp2, bufp))
+ || !TEST_str_eq(bufp2, "tuvwxyz")
+ || (tstid <= 1 && !TEST_ptr_eq(bufp2, bufp)))
goto err;
/* OCTET string */
- if (!TEST_ptr(cp = OSSL_PARAM_locate(params, "octstr"))
+ if (!TEST_ptr(cp = OSSL_PARAM_locate(p, "octstr"))
|| !TEST_true(OSSL_PARAM_set_octet_string(cp, "abcdefghi",
sizeof("abcdefghi")))
|| !TEST_size_t_eq(cp->return_size, sizeof("abcdefghi")))
@@ -580,19 +601,19 @@ static int test_param_construct(void)
goto err;
/* OCTET pointer */
vp = &l;
- if (!TEST_ptr(cp = OSSL_PARAM_locate(params, "octptr"))
+ if (!TEST_ptr(cp = OSSL_PARAM_locate(p, "octptr"))
|| !TEST_true(OSSL_PARAM_set_octet_ptr(cp, &ul, sizeof(ul)))
|| !TEST_size_t_eq(cp->return_size, sizeof(ul))
- || !TEST_ptr_eq(vp, &ul))
+ || (tstid <= 1 && !TEST_ptr_eq(vp, &ul)))
goto err;
/* Match the return size to avoid trailing garbage bytes */
cp->data_size = cp->return_size;
if (!TEST_true(OSSL_PARAM_get_octet_ptr(cp, (const void **)&vp2, &k))
|| !TEST_size_t_eq(k, sizeof(ul))
- || !TEST_ptr_eq(vp2, vp))
+ || (tstid <= 1 && !TEST_ptr_eq(vp2, vp)))
goto err;
/* BIGNUM */
- if (!TEST_ptr(cp = OSSL_PARAM_locate(params, "bignum"))
+ if (!TEST_ptr(cp = OSSL_PARAM_locate(p, "bignum"))
|| !TEST_ptr(bn = BN_lebin2bn(bn_val, (int)sizeof(bn_val), NULL))
|| !TEST_true(OSSL_PARAM_set_BN(cp, bn))
|| !TEST_size_t_eq(cp->data_size, cp->return_size))
@@ -604,6 +625,9 @@ static int test_param_construct(void)
goto err;
ret = 1;
err:
+ if (p != params)
+ OPENSSL_free(p);
+ OPENSSL_free(p1);
OPENSSL_free(vpn);
BN_free(bn);
BN_free(bn2);
@@ -637,6 +661,38 @@ static int test_param_modified(void)
return 1;
}
+static int test_param_copy_null(void)
+{
+ int ret, val;
+ int a = 1, b = 2, i = 0;
+ OSSL_PARAM *cp1 = NULL, *cp2 = NULL, *p;
+ OSSL_PARAM param[3];
+
+ param[i++] = OSSL_PARAM_construct_int("a", &a);
+ param[i++] = OSSL_PARAM_construct_int("b", &b);
+ param[i] = OSSL_PARAM_construct_end();
+
+ ret = TEST_ptr_null(OSSL_PARAM_dup(NULL))
+ && TEST_ptr(cp1 = OSSL_PARAM_merge(NULL, param))
+ && TEST_ptr(p = OSSL_PARAM_locate(cp1, "a"))
+ && TEST_true(OSSL_PARAM_get_int(p, &val))
+ && TEST_int_eq(val, 1)
+ && TEST_ptr(p = OSSL_PARAM_locate(cp1, "b"))
+ && TEST_true(OSSL_PARAM_get_int(p, &val))
+ && TEST_int_eq(val, 2)
+ && TEST_ptr(cp2 = OSSL_PARAM_merge(param, NULL))
+ && TEST_ptr(p = OSSL_PARAM_locate(cp2, "a"))
+ && TEST_true(OSSL_PARAM_get_int(p, &val))
+ && TEST_int_eq(val, 1)
+ && TEST_ptr(p = OSSL_PARAM_locate(cp2, "b"))
+ && TEST_true(OSSL_PARAM_get_int(p, &val))
+ && TEST_int_eq(val, 2)
+ && TEST_ptr_null(OSSL_PARAM_merge(NULL, NULL));
+ OSSL_PARAM_free(cp2);
+ OSSL_PARAM_free(cp1);
+ return ret;
+}
+
int setup_tests(void)
{
ADD_ALL_TESTS(test_param_int, OSSL_NELEM(raw_values));
@@ -651,7 +707,8 @@ int setup_tests(void)
ADD_ALL_TESTS(test_param_uint64, OSSL_NELEM(raw_values));
ADD_ALL_TESTS(test_param_bignum, OSSL_NELEM(raw_values));
ADD_TEST(test_param_real);
- ADD_TEST(test_param_construct);
+ ADD_ALL_TESTS(test_param_construct, 4);
ADD_TEST(test_param_modified);
+ ADD_TEST(test_param_copy_null);
return 1;
}