]> granicus.if.org Git - p11-kit/commitdiff
test: Add test for p11_attrs_purge()
authorDaiki Ueno <dueno@redhat.com>
Thu, 5 Apr 2018 14:03:07 +0000 (16:03 +0200)
committerDaiki Ueno <ueno@gnu.org>
Fri, 6 Apr 2018 16:27:24 +0000 (18:27 +0200)
common/test-attrs.c

index 79895e2d1d54640a8381f209869261c9328747f4..bc588c8d9eee1331be2551d6186fdbfa3309b050 100644 (file)
@@ -563,6 +563,34 @@ test_remove (void)
        p11_attrs_free (attrs);
 }
 
+static void
+test_purge (void)
+{
+       CK_BBOOL vtrue = CK_TRUE;
+       CK_ATTRIBUTE *attr;
+       CK_ATTRIBUTE *attrs;
+
+       CK_ATTRIBUTE initial[] = {
+               { CKA_LABEL, "label", 5 },
+               { CKA_TOKEN, &vtrue, sizeof (vtrue) },
+       };
+
+       attrs = p11_attrs_buildn (NULL, initial, 2);
+       assert_ptr_not_null (attrs);
+
+       attr = p11_attrs_find (attrs, CKA_LABEL);
+       assert_ptr_eq (attrs + 0, attr);
+
+       attr[0].ulValueLen = (CK_ULONG) -1;
+
+       p11_attrs_purge (attrs);
+
+       attr = p11_attrs_find (attrs, CKA_LABEL);
+       assert_ptr_eq (NULL, attr);
+
+       p11_attrs_free (attrs);
+}
+
 static void
 test_match (void)
 {
@@ -753,5 +781,6 @@ main (int argc,
        p11_test (test_find_value, "/attrs/find-value");
        p11_test (test_find_valid, "/attrs/find-valid");
        p11_test (test_remove, "/attrs/remove");
+       p11_test (test_purge, "/attrs/purge");
        return p11_test_run (argc, argv);
 }