1 #include <Security/SecKeychain.h>
2 #include <Security/SecKeychainSearch.h>
9 #include "testsecevent.h"
13 SecKeychainRef keychain
= NULL
;
14 ok_status(SecKeychainCreate("test", 4, "test", FALSE
, NULL
, &keychain
),
16 ok_status(test_sec_event_register(kSecEveryEventMask
),
17 "register for all events");
20 for (item_num
= 0; item_num
< item_count
; ++item_num
)
23 sprintf(account
, "account-%d", item_num
);
24 ok_status(SecKeychainAddGenericPassword(keychain
, 7, "service",
25 strlen(account
), account
, 4, "test", NULL
),
26 "add generic password");
28 SecKeychainAttribute attrs
[] =
29 { { kSecAccountItemAttr
} };
30 SecKeychainAttributeList attrList
=
31 { sizeof(attrs
) / sizeof(*attrs
), attrs
};
33 for (item_num
= 0; item_num
< item_count
- 2; ++item_num
)
36 sprintf(account
, "account-%d", item_num
);
37 SecKeychainItemRef item
= NULL
;
38 is_sec_event(kSecAddEvent
, NULL
, &item
, NULL
, "got add event");
41 skip("no item", 3, item
!= NULL
);
43 ok_status(SecKeychainItemCopyContent(item
, NULL
, &attrList
, NULL
,
44 NULL
), "get content");
46 eq_stringn(account
, strlen(account
), attrs
[0].data
, attrs
[0].length
,
47 "account name in notification matches");
48 ok_status(SecKeychainItemFreeContent(&attrList
, NULL
),
53 for (; item_num
< item_count
; ++item_num
)
56 sprintf(account
, "account-%d", item_num
);
57 SecKeychainItemRef item
= NULL
;
58 is_sec_event(kSecAddEvent
, NULL
, &item
, NULL
, "got add event");
61 skip("no item", 3, item
!= NULL
);
63 ok_status(SecKeychainItemCopyContent(item
, NULL
, &attrList
, NULL
,
64 NULL
), "get content");
65 eq_stringn(account
, strlen(account
), attrs
[0].data
, attrs
[0].length
,
66 "account name in notification matches");
67 ok_status(SecKeychainItemFreeContent(&attrList
, NULL
),
72 ok(tests_end(1), "cleanup");
75 int main(int argc
, char *const *argv
)
80 if (!tests_begin(argc
, argv
))
81 BAIL_OUT("tests_begin failed");