summaryrefslogtreecommitdiff
path: root/test/property_test.c
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2021-12-21 11:44:49 +1100
committerPauli <ppzgs1@gmail.com>2022-01-01 12:23:38 +1100
commit9f6841e9d8964943cf5f616543750cee85c4911c (patch)
treee6a4c181bab5f396865aca802f2f3012254f93be /test/property_test.c
parent2e3c59356f847a76a90f9f837d4983428df6eb19 (diff)
downloadopenssl-new-9f6841e9d8964943cf5f616543750cee85c4911c.tar.gz
test: add some unit tests for the property to string functions
That is: ossl_property_name_str and ossl_property_value_str. These only have high level tests during the creation of child library contexts. Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17325)
Diffstat (limited to 'test/property_test.c')
-rw-r--r--test/property_test.c61
1 files changed, 45 insertions, 16 deletions
diff --git a/test/property_test.c b/test/property_test.c
index ad44cf1513..14b891c3a0 100644
--- a/test/property_test.c
+++ b/test/property_test.c
@@ -50,30 +50,59 @@ static void down_ref(void *p)
static int test_property_string(void)
{
- OSSL_METHOD_STORE *store;
+ OSSL_LIB_CTX *ctx;
+ OSSL_METHOD_STORE *store = NULL;
int res = 0;
OSSL_PROPERTY_IDX i, j;
- if (TEST_ptr(store = ossl_method_store_new(NULL))
- && TEST_int_eq(ossl_property_name(NULL, "fnord", 0), 0)
- && TEST_int_ne(ossl_property_name(NULL, "fnord", 1), 0)
- && TEST_int_ne(ossl_property_name(NULL, "name", 1), 0)
+ /*-
+ * Use our own library context because we depend on ordering from a
+ * pristine state.
+ */
+ if (TEST_ptr(ctx = OSSL_LIB_CTX_new())
+ && TEST_ptr(store = ossl_method_store_new(ctx))
+ && TEST_int_eq(ossl_property_name(ctx, "fnord", 0), 0)
+ && TEST_int_ne(ossl_property_name(ctx, "fnord", 1), 0)
+ && TEST_int_ne(ossl_property_name(ctx, "name", 1), 0)
+ /* Pre loaded names */
+ && TEST_str_eq(ossl_property_name_str(ctx, 1), "provider")
+ && TEST_str_eq(ossl_property_name_str(ctx, 2), "version")
+ && TEST_str_eq(ossl_property_name_str(ctx, 3), "fips")
+ && TEST_str_eq(ossl_property_name_str(ctx, 4), "output")
+ && TEST_str_eq(ossl_property_name_str(ctx, 5), "input")
+ && TEST_str_eq(ossl_property_name_str(ctx, 6), "structure")
+ /* The names we added */
+ && TEST_str_eq(ossl_property_name_str(ctx, 7), "fnord")
+ && TEST_str_eq(ossl_property_name_str(ctx, 8), "name")
+ /* Out of range */
+ && TEST_ptr_null(ossl_property_name_str(ctx, 0))
+ && TEST_ptr_null(ossl_property_name_str(ctx, 9))
/* Property value checks */
- && TEST_int_eq(ossl_property_value(NULL, "fnord", 0), 0)
- && TEST_int_ne(i = ossl_property_value(NULL, "no", 0), 0)
- && TEST_int_ne(j = ossl_property_value(NULL, "yes", 0), 0)
+ && TEST_int_eq(ossl_property_value(ctx, "fnord", 0), 0)
+ && TEST_int_ne(i = ossl_property_value(ctx, "no", 0), 0)
+ && TEST_int_ne(j = ossl_property_value(ctx, "yes", 0), 0)
&& TEST_int_ne(i, j)
- && TEST_int_eq(ossl_property_value(NULL, "yes", 1), j)
- && TEST_int_eq(ossl_property_value(NULL, "no", 1), i)
- && TEST_int_ne(i = ossl_property_value(NULL, "illuminati", 1), 0)
- && TEST_int_eq(j = ossl_property_value(NULL, "fnord", 1), i + 1)
- && TEST_int_eq(ossl_property_value(NULL, "fnord", 1), j)
+ && TEST_int_eq(ossl_property_value(ctx, "yes", 1), j)
+ && TEST_int_eq(ossl_property_value(ctx, "no", 1), i)
+ && TEST_int_ne(i = ossl_property_value(ctx, "illuminati", 1), 0)
+ && TEST_int_eq(j = ossl_property_value(ctx, "fnord", 1), i + 1)
+ && TEST_int_eq(ossl_property_value(ctx, "fnord", 1), j)
+ /* Pre loaded values */
+ && TEST_str_eq(ossl_property_value_str(ctx, 1), "yes")
+ && TEST_str_eq(ossl_property_value_str(ctx, 2), "no")
+ /* The value we added */
+ && TEST_str_eq(ossl_property_value_str(ctx, 3), "illuminati")
+ && TEST_str_eq(ossl_property_value_str(ctx, 4), "fnord")
+ /* Out of range */
+ && TEST_ptr_null(ossl_property_value_str(ctx, 0))
+ && TEST_ptr_null(ossl_property_value_str(ctx, 5))
/* Check name and values are distinct */
- && TEST_int_eq(ossl_property_value(NULL, "cold", 0), 0)
- && TEST_int_ne(ossl_property_name(NULL, "fnord", 0),
- ossl_property_value(NULL, "fnord", 0)))
+ && TEST_int_eq(ossl_property_value(ctx, "cold", 0), 0)
+ && TEST_int_ne(ossl_property_name(ctx, "fnord", 0),
+ ossl_property_value(ctx, "fnord", 0)))
res = 1;
ossl_method_store_free(store);
+ OSSL_LIB_CTX_free(ctx);
return res;
}