1 #include <Security/SecKeychain.h>
2 #include <Security/SecKeychainSearch.h>
9 #include "testsecevent.h"
11 static char account
[] = "account";
12 static char service
[] = "service";
13 static char password
[] = "password";
15 void tests(int dont_skip
)
17 SecKeychainRef keychain
= NULL
;
18 ok_status(SecKeychainCreate("test", 4, "test", FALSE
, NULL
, &keychain
),
20 ok_status(test_sec_event_register(kSecEveryEventMask
),
21 "register for all events");
22 SecKeychainItemRef itemRef
;
23 ok_status(SecKeychainAddGenericPassword(keychain
,
24 sizeof(account
), account
,
25 sizeof(service
), service
,
26 sizeof(password
), password
,
28 "add generic password, wait for callback");
29 SecKeychainRef eventKeychain
= NULL
;
30 SecKeychainItemRef eventItem
= NULL
;
31 is_sec_event(kSecAddEvent
, &eventKeychain
, &eventItem
, NULL
,
33 is(eventItem
, itemRef
, "add event item matches");
34 is(eventKeychain
, keychain
, "add event keychain matches");
35 CFRelease(eventKeychain
);
40 ok_status(SecKeychainItemDelete(itemRef
), "delete item");
41 is_sec_event(kSecDeleteEvent
, &eventKeychain
, &eventItem
, NULL
,
43 is(eventItem
, itemRef
, "delete event item matches");
44 is(eventKeychain
, keychain
, "delete event keychain matches");
45 if (eventKeychain
!= NULL
) // eventKeychain can be null if the test times out
47 CFRelease(eventKeychain
);
51 if (eventItem
!= NULL
)
57 no_sec_event("no event");
58 ok_status(test_sec_event_deregister(), "deregister events.");
64 ok(tests_end(1), "cleanup");
67 int main(int argc
, char *const *argv
)
70 int dont_skip
= argc
> 1 && !strcmp(argv
[1], "-s");
73 if (!tests_begin(argc
, argv
))
74 BAIL_OUT("tests_begin failed");