summaryrefslogtreecommitdiff
path: root/common/tests
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2013-03-18 13:13:24 +0100
committerStef Walter <stefw@gnome.org>2013-03-18 13:13:24 +0100
commita904e98b78b55e7a6213356225e45a04fdc457e1 (patch)
treee879e446a5402e59f4be13b7711e071c858edc26 /common/tests
parentf71baf6adf00626e73326149d55183bc62f827ae (diff)
Refine looking up of attributes in arrays
There was a class of bugs for looking up invalid or empty attributes in the internal PKCS#11 attribute arrays. * Refine what p11_attrs_find_valid() treats as valid * Rename p11_attrs_is_empty() to p11_attrs_terminator() for clarity
Diffstat (limited to 'common/tests')
-rw-r--r--common/tests/test-attrs.c54
1 files changed, 51 insertions, 3 deletions
diff --git a/common/tests/test-attrs.c b/common/tests/test-attrs.c
index 49350be..f1e6d91 100644
--- a/common/tests/test-attrs.c
+++ b/common/tests/test-attrs.c
@@ -43,6 +43,21 @@
#include "debug.h"
static void
+test_terminator (CuTest *tc)
+{
+ CK_ATTRIBUTE attrs[] = {
+ { CKA_LABEL, "label", 5 },
+ { CKA_LABEL, NULL, 0 },
+ { CKA_INVALID },
+ };
+
+ CuAssertIntEquals (tc, true, p11_attrs_terminator (attrs + 2));
+ CuAssertIntEquals (tc, true, p11_attrs_terminator (NULL));
+ CuAssertIntEquals (tc, false, p11_attrs_terminator (attrs));
+ CuAssertIntEquals (tc, false, p11_attrs_terminator (attrs + 1));
+}
+
+static void
test_count (CuTest *tc)
{
CK_BBOOL vtrue = CK_TRUE;
@@ -647,22 +662,53 @@ test_find_ulong (CuTest *tc)
}
static void
+test_find_value (CuTest *tc)
+{
+ void *value;
+ size_t length;
+
+ CK_ATTRIBUTE attrs[] = {
+ { CKA_LABEL, "", (CK_ULONG)-1 },
+ { CKA_LABEL, NULL, 5 },
+ { CKA_LABEL, "", 0 },
+ { CKA_LABEL, "test", 4 },
+ { CKA_VALUE, NULL, 0 },
+ { CKA_INVALID },
+ };
+
+ value = p11_attrs_find_value (attrs, CKA_LABEL, &length);
+ CuAssertPtrEquals (tc, attrs[3].pValue, value);
+ CuAssertIntEquals (tc, 4, length);
+
+ value = p11_attrs_find_value (attrs, CKA_LABEL, NULL);
+ CuAssertPtrEquals (tc, attrs[3].pValue, value);
+
+ value = p11_attrs_find_value (attrs, CKA_VALUE, &length);
+ CuAssertPtrEquals (tc, NULL, value);
+
+ value = p11_attrs_find_value (attrs, CKA_TOKEN, &length);
+ CuAssertPtrEquals (tc, NULL, value);
+}
+
+static void
test_find_valid (CuTest *tc)
{
CK_ATTRIBUTE *attr;
CK_ATTRIBUTE attrs[] = {
{ CKA_LABEL, "", (CK_ULONG)-1 },
+ { CKA_LABEL, NULL, 5 },
+ { CKA_LABEL, "", 0 },
{ CKA_LABEL, "test", 4 },
- { CKA_VALUE, NULL, 0 },
+ { CKA_VALUE, "value", 5 },
{ CKA_INVALID },
};
attr = p11_attrs_find_valid (attrs, CKA_LABEL);
- CuAssertPtrEquals (tc, attrs + 1, attr);
+ CuAssertPtrEquals (tc, attrs + 3, attr);
attr = p11_attrs_find_valid (attrs, CKA_VALUE);
- CuAssertPtrEquals (tc, attrs + 2, attr);
+ CuAssertPtrEquals (tc, attrs + 4, attr);
attr = p11_attrs_find_valid (attrs, CKA_TOKEN);
CuAssertPtrEquals (tc, NULL, attr);
@@ -682,6 +728,7 @@ main (void)
SUITE_ADD_TEST (suite, test_hash);
SUITE_ADD_TEST (suite, test_to_string);
+ SUITE_ADD_TEST (suite, test_terminator);
SUITE_ADD_TEST (suite, test_count);
SUITE_ADD_TEST (suite, test_build_one);
SUITE_ADD_TEST (suite, test_build_two);
@@ -702,6 +749,7 @@ main (void)
SUITE_ADD_TEST (suite, test_findn);
SUITE_ADD_TEST (suite, test_find_bool);
SUITE_ADD_TEST (suite, test_find_ulong);
+ SUITE_ADD_TEST (suite, test_find_value);
SUITE_ADD_TEST (suite, test_find_valid);
SUITE_ADD_TEST (suite, test_remove);