1 #include <Security/SecKeychain.h>
2 #include <Security/SecKeychainItem.h>
12 SecKeychainRef keychain
;
13 ok_status(SecKeychainCreate("test", 4, "test", FALSE
, NULL
, &keychain
),
15 SecKeychainItemRef item
= NULL
;
16 ok_status(SecKeychainAddGenericPassword(keychain
, 7, "service", 7,
17 "account", 4, "test", &item
), "add generic password");
18 ok(item
, "is item non NULL");
19 SecKeychainItemRef oldItem
= item
;
20 is_status(SecKeychainAddGenericPassword(keychain
, 7, "service", 7,
21 "account", 4, "test", &oldItem
),
22 errSecDuplicateItem
, "add generic password again");
23 is((intptr_t)item
, (intptr_t)oldItem
, "item is unchanged");
25 SecItemClass itemClass
= 0;
26 SecKeychainAttribute attrs
[] =
28 { kSecAccountItemAttr
},
29 { kSecServiceItemAttr
}
31 SecKeychainAttributeList attrList
= { sizeof(attrs
) / sizeof(*attrs
), attrs
};
34 ok_status(SecKeychainItemCopyContent(item
, &itemClass
, &attrList
, &length
, &data
), "SecKeychainItemCopyContent");
35 ok_status(SecKeychainItemFreeContent(&attrList
, data
), "SecKeychainItemCopyContent");
37 is(CFGetRetainCount(item
), 1, "item retaincount is 1");
38 is(CFGetRetainCount(keychain
), 2, "keychain retaincount is 2");
40 is(CFGetRetainCount(keychain
), 1, "keychain retaincount is 1");
41 ok_status(SecKeychainDelete(keychain
), "delete keychain");
45 int main(int argc
, char *const *argv
)
49 if (!tests_begin(argc
, argv
))
50 BAIL_OUT("tests_begin failed");
53 ok(tests_end(1), "cleanup");