1 #include <Security/SecKeychain.h>
2 #include <Security/SecKeychainItem.h>
6 #include "keychain_regressions.h"
7 #include "kc-helpers.h"
9 static void tests(void)
11 SecKeychainRef keychain
= getPopulatedTestKeychain();
12 SecKeychainItemRef item
= NULL
;
13 ok_status(SecKeychainAddGenericPassword(keychain
, 7, "service", 7,
14 "account", 4, "test", &item
), "add generic password");
15 ok(item
, "is item non NULL");
16 SecKeychainItemRef oldItem
= item
;
17 is_status(SecKeychainAddGenericPassword(keychain
, 7, "service", 7,
18 "account", 4, "test", &oldItem
),
19 errSecDuplicateItem
, "add generic password again");
20 is((intptr_t)item
, (intptr_t)oldItem
, "item is unchanged");
22 SecItemClass itemClass
= 0;
23 SecKeychainAttribute attrs
[] =
25 { kSecAccountItemAttr
},
26 { kSecServiceItemAttr
}
28 SecKeychainAttributeList attrList
= { sizeof(attrs
) / sizeof(*attrs
), attrs
};
31 ok_status(SecKeychainItemCopyContent(item
, &itemClass
, &attrList
, &length
, &data
), "SecKeychainItemCopyContent");
32 eq_string(data
, "test", "Item data is wrong");
33 ok_status(SecKeychainItemFreeContent(&attrList
, data
), "SecKeychainItemCopyContent");
35 is(CFGetRetainCount(item
), 1, "item retaincount is 1");
36 is(CFGetRetainCount(keychain
), 2, "keychain retaincount is 2");
38 is(CFGetRetainCount(keychain
), 1, "keychain retaincount is 1");
39 ok_status(SecKeychainDelete(keychain
), "delete keychain");
43 int kc_10_item_add_generic(int argc
, char *const *argv
)
45 initializeKeychainTests("kc-10-item-add-generic");